假设我有一张名字和生日字段的表格。我可以使用此SQL返回共享同一个生日的项目表(例如,4个人的生日为4/8/1995):
SELECT DISTINCT "Birthday", COUNT("Birthday") as "FieldCount"
FROM "test_main" Group BY "Birthday" Order By "FieldCount" DESC
但是如何修改我选择忽略年份的值,例如按月计算生日数,例如,Jan:42名,2月:28名等
由于
答案 0 :(得分:2)
SELECT month(Birthday), COUNT(Birthday)
FROM test_main
Group BY month(Birthday)
Order By COUNT(Birthday) DESC
答案 1 :(得分:1)
一种方法是使用内置函数来提取年份和月份:
SELECT month(birthday), count(*) as FieldCount
FROM test_main
Group BY month(birthday)
Order By FieldCount DESC;
注意:
distinct
不需要group by
。COUNT(*)
应该找到你想要的东西。