学习group by语法

group by 经常与聚合函数一起使用。

(1)出现在select后面的字段 要么是聚合函数中的,要么就是group by中的。

(2)如果有其他筛选条件,先使用where 在使用group by,where更高。

使用下表进行举例说明

a b c
1 a
1 a
1 a
1 a
1 a
1 b
1 b
1 b

select count(a),b from test group by b;

  b
5 a
3 b

select count(a),b,c from test group by c,b;

  b c
 4 a
 1 a
 3 b
posted @ 2018-04-28 17:55  radiant13  阅读(425)  评论(0编辑  收藏  举报