请查看我的表结构:
-------------
| id | name |
-------------
| 1 | a |
| 2 | a |
| 3 | a |
| 4 | b |
| 5 | b |
| 6 | c |
| 7 | d |
| 8 | d |
我想创建一个查询(在PHP中),以获得这样的结果(用HTML格式):
<p>name: a (number of letters: 3)</p>
<p>name: b (number of letters: 2)</p>
<p>name: c (number of letters: 1)</p>
<p>name: d (number of letters: 2)</p>
答案 0 :(得分:5)
SELECT count(name),
name
FROM MyTable
GROUP BY name
ORDER BY name ASC;
我假设您的表名为MyTable
,因此会进行更换。