1、GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组。(也就是说group by 和聚合函数结合起来使用,要查询的结果来没有聚合函数则报错:不是group by 表达式)
a、where 不能放在group by 后面使用
b、having 要和group by 连在一起使用,作用相当于where
c、where后面的条件中不能跟聚合函数,但是having 可以
示例:
正确:select t.ssdw,count(t.ssdw) from FL_SSDW t group by t.ssdw having t.ssdw='二厂';
select t.ssdw,count(t.ssdw) from FL_SSDW t group by t.ssdw having count(t.ssdw)=1
select * from gc_gd_xgnfrbsh where djgdssdw is null
错误:select t.ssdw,count(t.ssdw) from FL_SSDW t group by t.ssdw where t.ssdw='二厂';
select * from gc_gd_xgnfrbsh having djgdssdw is null