Back to Yugabyte Db

ROLLUP

community/learn/content/01-SQL-Basics/02-fundamentals/18-rollup.md

2026.1.0.0-b25802 B
Original Source

SELECT with a GROUP BY and ROLLUP

In this exercise we will query the products table, group the results by product_id and then generate multiple grouping sets from the results using ROLLUP.

SELECT product_id,
       supplier_id,
       product_name,
       SUM(units_in_stock)
FROM products
GROUP BY product_id,
         ROLLUP(supplier_id);

This query should return 154 rows

SELECT with a GROUP BY and PARTIAL ROLLUP

In this exercise we will query the products table, group the results by product_id and then generate multiple grouping sets from the results using ROLLUP.

SELECT product_id,
       supplier_id,
       product_name,
       SUM(units_in_stock)
FROM products
GROUP BY product_id ROLLUP(supplier_id, product_id);

This query should return TBD rows