我有一个数据库:


pID    |type| City     |
------------------
Z0D12  | Z  | Amsterdam
XOD12  | X  | Paris
YOD12  | Y  | Madrid
GOD12  | G  | Amsterdam
GOD12  | G  | Amsterdam


我有带日期行的复合键,因此pID可以重复

我想显示每种类型的城市出现的次数:


City       |type    | amountoftimes |
------------------
Amsterdam  | Z      | 1
Amsterdam  | G      | 2
Paris      | X      | 1
Madrid     | Y      | 1



我该怎么做呢?

最佳答案

它将类似于:

select citiTable.city, citiTable.type, count(*) as amountOfTimes
from citiTable
group by citiTable.city, citiTable.type


有关如何使用计数的文档可以找到here

关于mysql - 如何根据类型获取值的数量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56728267/

10-12 01:06