← Back to PostgreSQL Course | Chapter 7: Aggregations & Grouping | Lesson 5 of 7

ROLLUP का उपयोग

ROLLUP एक grouped result में subtotal और grand total rows add करता है।

In this page:

  1. ROLLUP
Syntax
sql
SELECT column1, column2, aggregate_function(column)
FROM table_name
GROUP BY ROLLUP (column1, column2);

ROLLUP

GROUP BY ROLLUP (a, b) (a, b) के लिए groups produce करता है, फिर (a) के लिए subtotals और () के लिए एक grand total।

Subtotal rows rolled-up columns में NULL दिखाती हैं। GROUPING() function real NULLs को subtotal NULLs से अलग बताता है।

यह reports के लिए PostgreSQL syntax है; site editor का SQLite इसे support नहीं करता।

Note: Subtotal rows label करने के लिए GROUPING(col) इस्तेमाल करें।

उदाहरण: ROLLUP

bash
shop=# SELECT region, item, SUM(qty) AS total
shop-# FROM sales GROUP BY ROLLUP (region, item) ORDER BY region, item;
 region | item | total
--------+------+-------
 N      | book |     1
 N      | lamp |     2
 N      | pen  |     5
 N      |      |     8
 S      | book |     3
 S      | pen  |    10
 S      |      |    13
        |      |    21

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. subtotal NULLs को data NULLs से confuse करना
  2. इसे SQLite में expect करना
  3. ORDER BY भूल जाना
चैप्टर सारांश
  • ROLLUP subtotals और एक grand total add करता है
  • Subtotal rows में NULL है
  • GROUPING() इन्हें identify करता है
  • Report totals के लिए great
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.