更新时间:2024-07-17 GMT+08:00
分析语句-GROUP BY
按值分组。
按字段的值分组
SELECT age GROUP BY age
age |
---|
28 |
32 |
36 |
按字段别名分组
SELECT account_number AS num GROUP BY num
num |
---|
1 |
16 |
13 |
18 |
按多个字段分组
SELECT account_number AS num, age GROUP BY num, age
num |
age |
---|---|
1 |
32 |
16 |
36 |
13 |
28 |
18 |
32 |
使用SQL函数
函数相关内容请参见函数。
SELECT LENGTH(lastname) AS len, COUNT(*) AS count GROUP BY LENGTH(lastname)
len |
count |
---|---|
4 |
2 |
5 |
2 |
父主题: 查询与分析语法-SQL语法