--以下两条sql语句,查询结果一模一样,区别是,一个是分组前用where加限定条件,一个是分组后,使用having 加限定条件,查询结果都一样.
select count(*) '停用总数' from v3.dbo.t_userinfo where f_user_state = '停用' group by f_user_state --group by 分组前,使用where加限定条件
select count(*) '停用总数' from v3.dbo.t_userinfo group by f_user_state having f_user_state = '停用' --group by 分组之后,必须用having加限定条件,也就是 HAVING子句在聚合后对组记录进行筛选