Conditional aggregate with Group By clause
问题 I'm trying to do this with HiveQL but I don't know how to do this in SQL neither. Table structure as follows: id1 id2 category 123 abc 1 123 def 1 123 def 2 456 abc 1 123 abc 1 123 abc 2 ... I'd like to write a query that outputs: key count category1count category2count 123-abc 3 2 1 123-def 2 1 1 456-abc 1 1 0 So far I've got this: SELECT concat( concat(id1,'-'), id2), count(*) , count( SELECT * WHERE buyingcategory = 1 ??? ) , count( SELECT * WHERE buyingcategory = 2 ??? ) FROM table GROUP