To group data using GROUP BY, you can use the following sample syntax. WHERE and ORDER BY are optional:
SELECT column(s)
FROM table
WHERE condition(s)
GROUP BY columns(s)
ORDER BY column(s);
To get subtotals and totals with GROUP BY and ROLLUP, you can use the following sample syntax:
SELECT col1, col2, col3
FROM table
GROUP BY col2, col1, WITH ROLLUP;