中国石凳联盟 登录注册

GROUP BY 子句

摇滚时代··1 回复·248 浏览

发表回复

简单的说就是分组,主要配合Count,AVG,SUM等函数使用。


分组的作用是
避免重复行的引用
。


比如一个表"stoneren"



name age



rock 15


rj45 15


penny 20


fulltime 20


csww 21


先看 Select * From Stoneren


返回


rock 15


rj45 15


penny 20


fulltime 20


csww 21


而 Select * From Stoneren Group BY Age


返回


rock 15


fulltime 20


csww 21


以AGE分组,只返回age不同的行,相同的被剔除。当然,这样的Select并没有特别大的实际意义,但是在求平均(AVG),求和(SUM)等的时候就显得很关键了。例如


Select AVG(age) as 石凳平均年龄 From Stoneren Group BY Age


则只返回一行记录。



点赞0 收藏
略有所闻
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
发表回复
发表回复