需求描述:
根据列username,对列subject的数量进行统计
表的记录集:
+----+---------+----------+
| id | subject | username |
+----+---------+----------+
| 1 | 记录一 | admin |
| 2 | 记录二 | admin |
| 3 | 记录三 | admin |
| 4 | 记录四 | test1 |
| 5 | 记录五 | test2 |
| 6 | 记录六 | test2 |
+----+---------+----------+
需要的结果:
+----------+-----+
| username | num |
+----------+-----+
| admin | 3 |
| test1 | 1 |
| test2 | 2 |
+----------+-----+
SQL:select username,count(subject) as num from 表名 group by username