Need an SQL query to count unique combinations of strings
I have a postgres table that looks in part like:
Year | Month | ...... (more columns)
"2004" | "09" | ......
"2004" | "09" | ......
"2004" | "09" | ......
"2004" | "10" | ......
"2004开发者_开发技巧" | "11" | ......
"2004" | "11" | ......
"2004" | "12" | ......
"2005" | "01" | ......
"2005" | "01" | ......
Yes, these are all strings. Don't ask me why.
I'm trying to figure out a single SQL query that will tell me how many rows have each combination of year and month. I.e, "2004" and "09" => 3, "2004" and "10" => 1, "2004" and "11" => 2, etc. When I try to do a COUNT(year,month) I get an error that I can't use that function on character varying columns.
select Year, Month, count(*)
from your_table
group by Year, Month
精彩评论