tags:

views:

77

answers:

1

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.

+4  A: 
select Year, Month, count(*)
from your_table
group by Year, Month
skwllsp
Argh, of course. Thanks!
PreciousBodilyFluids