我是新来的,所以如果它没有固定的主题,请修复我。 我有这张表:
id | uid | month | year
-----------------------
1 | 5 | 12 | 2018
2 | 5 | 12 | 2018
3 | 9 | 12 | 2018
4 | 3 | 01 | 2019
我想计算每个uid
有多少次month
和year
值等于 - month=12
和 year=2018
例如我想得到这样的响应:
uid=5 - count = 2
uid=9 - count = 1
这怎么可能?
最佳答案
使用按 uid 分组
:
select uid, count(*) as counter
from table
where month = 12 and year = 2018
group by uid
关于php - 如何计算 SQL 中每个值的表行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53977788/