Ave*_*Joe 3 php mysql sql database
这是我得到的mySQL
id terms
1 a
2 c
3 a
4 b
5 b
6 a
7 a
8 b
9 b
10 b
Run Code Online (Sandbox Code Playgroud)
我希望得到按字母排序的按字母顺序排列的列表,如下所示
terms count
a 4
b 5
c 1
Run Code Online (Sandbox Code Playgroud)
我需要什么mySQL语句?
我相信这样的事情会起作用:
SELECT terms, COUNT( id) AS count
FROM table
GROUP BY terms
ORDER BY terms DESC
Run Code Online (Sandbox Code Playgroud)
通过SQL中的一个或多个列或表达式的值将选定的一组行分组到一组摘要行中.每组返回一行.SELECT子句列表中的聚合函数提供有关每个组而不是单个行的信息.
你只需要申请group by获得结果的条款
select terms, count (id) as count from table
group by terms
order by terms
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
282 次 |
| 最近记录: |