Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is ROLLUP?

SQL · Aggregations & Grouping

What is ROLLUP?

Mediumsql-14
rollupsubtotalsgrouping

Question

What is ROLLUP?

Solution

ROLLUP generates subtotals and a grand total.

Example:

SELECT department, team, SUM(salary)
FROM employees
GROUP BY ROLLUP(department, team);

It can produce:

IT       Backend      100000
IT       Frontend      80000
IT       NULL         180000   ← IT subtotal
HR       Recruitment   50000
HR       NULL          50000   ← HR subtotal
NULL     NULL         230000   ← Grand total

Useful for reports.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext