[英]How to count the number of a value in each month and year? SQL
how can I count the number of 'cancel' value in each month and year?如何计算每个月和每年的“取消”值的数量? Thank you!
谢谢!
res date
---------------------------------------
cancel 2022-05-02
cancel 2022-04-22
cancel 2022-04-08
cancel 2022-03-01
MS SQL微软 SQL
expected output:预期输出:
month&year numcases
-------------------------------
05-2022 300
04-2022 543
ETC.... ETC....
You can start trying something like this:你可以开始尝试这样的事情:
SELECT YEAR([date]), MONTH([date]), COUNT(*) AS [Number]
FROM [Table]
GROUP BY YEAR([date]), MONTH([date])
The column [date] should be datetime. [日期] 列应该是日期时间。 If it's text you will have to cast it:
如果是文本,您将不得不对其进行转换:
SELECT YEAR(CAST([date] AS datetime)), ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.