sql的一些知识_数据分组

group by--------按**分组查询

SELECT rank, MIN(weight)as min_weight FROM userinfo GROUP BY rank

对分组的值进行过滤需要使用HAVING,where只能对特定行的值进行过滤(另一种理解:分组前过滤:where;分组后过滤:having)

SELECT rank,MIN(weight)as min_weight FROM userinfo GROUP BY rank HAVING MIN(weight)>60

SELECT rank,COUNT(*)AS num FROM userinfo WHERE weight>50 GROUP BY rank HAVING COUNT(*)>3

顺序

select 语句中的使用顺序

 

posted @ 2017-11-19 00:57  月河  阅读(129)  评论(0编辑  收藏  举报