更新时间:2024-07-17 GMT+08:00

分析语句-GROUP BY

按值分组。

按字段的值分组

SELECT age GROUP BY age
表1 按字段的值分组

age

28

32

36

按字段别名分组

SELECT account_number AS num GROUP BY num
表2 按字段别名分组

num

1

16

13

18

按多个字段分组

SELECT account_number AS num, age GROUP BY num, age
表3 按多个字段分组

num

age

1

32

16

36

13

28

18

32

使用SQL函数

函数相关内容请参见函数

SELECT LENGTH(lastname) AS len, COUNT(*) AS count GROUP BY LENGTH(lastname)
表4 使用SQL函数

len

count

4

2

5

2