我有一个db:
---------------------
| section | name |
---------------------
| food | steak |
---------------------
| food | chicken |
---------------------
| drink | water |
---------------------
| food | pork |
---------------------
| drink | soda |
---------------------
| drink | steak |
---------------------
我正在尝试计算每个部分的行数。问题是,我没有静态部分名称。我试图用一个查询来做。
以下是我要找的结果:
-------------
| food | 3 |
-------------
| drink | 3 |
-------------
答案 0 :(得分:3)
SELECT section, COUNT(name) FROM table_name GROUP BY section