4.where不能使用聚合函数、having中可以使用聚合函数
#筛选出北京西城、东城、海淀及各区学校数量
SELECT region,count(school)
FROM T02_Bejing_school
WHERE region IN (‘海淀’ , ‘西城’ , ‘东城’) GROUP BY region;
#筛选出北京西城、东城、海淀三个区中学校数量超过10所的区及各区学校数量。
SELECT region,count(school)
FROM T02_Bejing_school
WHERE region IN (‘海淀’ , ‘西城’ , ‘东城’)
GROUP BY region HAVING count(school) > 10;
错误写法
SELECT region,count(school)
FROM T02_Bejing_school
WHERE region IN ('海淀' , '西城' , '东城') and count(school) > 10
GROUP BY region HAVING ;