MySQL --- Filter

 

 


--Grouping to select the number of SELECT COUNT (StudentName) as, sGrade as Grade
FROM S2
WHERE StudentNo> 5
--WHERE Address like '% 上海%'
GROUP BY SGrade
HAVING COUNT (StudentNo)> 1 |

 

 The difference between WHERE and HAVING

    1.The Where statement is read one by one from the disk, and then judged, the conditions are stored in the memory, and the ignore is not satisfied, and having is to read all the data into the memory, and then judge one by one inside the memory, not directly satisfied Delete (where is to determine when data is read from disk into memory, having is to determine all conditions before grouping statistics)
    2. Field alias can be used in the having clause, and where cannot be used
    3.having can use statistical functions, but where cannot
    You cannot follow the aggregate function after using 4.where, because the execution order of where is greater than the aggregate function.
    5.having is a filter group and where is a filter record

Guess you like

Origin www.cnblogs.com/cxiaojie/p/12738235.html