Reputation: 491
Let's say I have a table with name and birthday fields. I can use this SQL to return a table of items sharing the same birthday (e.g. 4 people have the birthday 4/8/1995):
SELECT DISTINCT "Birthday", COUNT("Birthday") as "FieldCount"
FROM "test_main" Group BY "Birthday" Order By "FieldCount" DESC
But how can I modify the value that I select to ignore the year, e.g. get a count of birthdays by month, for example, Jan: 42 names, Feb: 28 names, etc
Thanks
Upvotes: 0
Views: 35
Reputation: 1271191
One way is to use built in functions to extract the year and month:
SELECT month(birthday), count(*) as FieldCount
FROM test_main
Group BY month(birthday)
Order By FieldCount DESC;
Notes:
distinct
with a group by
.COUNT(*)
should be find for what you want.Upvotes: 1
Reputation: 204924
SELECT month(Birthday), COUNT(Birthday)
FROM test_main
Group BY month(Birthday)
Order By COUNT(Birthday) DESC
Upvotes: 2