SQL中Having与Where的区别
时间:2020-11-19 14:19 作者:admin610456
含义
where
在分组之前就进行选择操作
having
having在分组操作之后才进行选择操作,所以having可以选择聚合函数
eg:
// 下面这句是可以的SELECT COUNT(*) FROM AWHERE A.a1>0GROUP BY a2;
//但是下面就不行SELECT COUNT(*) FROM AWHERE A.a1>0 and count(*)>1GROUP BY a2;
//必须要改为havingSELECT COUNT(*) FROM AWHERE A.a1>0GROUP BY a2HAVING COUNT(*)>1
(责任编辑:admin)