sql - Counting same column multiple times, already grouped -
i'm trying count "y"s , "n"s in 1 column group them column. can pull "y" or "n" where:
select table2.group_by_this,count(table1.flag) table1 inner join table2 on table1.primary_key = table2.foreign_key table1.flag_required = "y" group table2.group_by_this
and can see "y"s , "n"s whole data set , not grouped other column using first answer here: sql - counting column twice i'm not sure how desired outcome should little this:
group_by_this y count n count ------------------------------- group1 10 1 group2 10 100 group3 0 10 group4 50 500 group5 1000 0
do need further grouping somehow?
select table2.group_by_this , count(case when table1.flag = 'y' 1 end) , count(case when table1.flag = 'n' 1 end) table1 join table2 on table1.primary_key = table2.foreign_key group table2.group_by_this
Comments
Post a Comment