select A, B, C, group_id, count(A) from tableName group by --declare columns A, B, C grouping sets ( (A,C), (A,B), (B,C), (C) )