I have a table with column names:
category1, category2, category3, Value
I want to get the following combinations from table:
---> category1,count(*)
---> category1, category2, count(*)
---> category2, category3, count(*)
Is there a way to do this in just one query or do I really need to write 3 separate queries? I am thinking of design like following:
Category1, Category2, Category3, CountNumber
Where the for case 1, category2 and category3 columns would be blank and for case 2 category 3 column would be blank, etc.
--------EXAMPLE---------------------------------------------------------
Cat1 Cat2 Cat3 Value
a NULL d1 13
b e1 d1 13
a e2 d1 13
c NULL d2 13
a e1 d1 13
a NULL d1 13
--------DESIRED OUTPUT -------------------------------------------------
Cat1 Cat2 Cat3 CountNumber
a NULL NULL 4
b NULL NULL 1
c NULL NULL 1
a e1 NULL 1
c e1 NULL 0
NULL e1 d1 2
and so on
Thanks
Try this
To insert rows in tmp table