Group by 注意事项:对查询的列有限制,除了聚合函数外,就必须是分组的项
order by总是放在最后
代码示例:
select Gender as 性别 ,count (Gender) as 总和 from UserInfo
GROUP by Gender
备注:
Where和having的区别:
Where是在分组之前的查询,having是在分组之后的进行查询
order by排序必须在最后
代码示例:
--分组查询 group by
select Gender as 性别, count (Gender) as 总和 from UserInfo
GROUP by Gender
orderby Gender desc
--如何对分组之后的结果进行筛选HAVING
select Gender as 性别,count(Gender) as 总和 from UserInfo
GROUP by Gender
having count(Gender)>6
order by Gender desc