SELECT c1, c2, aggregate (c3) FROM table GROUP BY GROUPING SETS ( (c1, c2), (c1), (c2), () );