学习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
  a
  a
  b

猜你喜欢

转载自www.cnblogs.com/ljf-Sky/p/8969076.html