GROUPING SETS का उपयोग
GROUPING SETS आपको एक query में कई अलग groupings compute करने देता है।
In this page:
Syntax
SELECT column1, column2, aggregate_function(column)
FROM table_name
GROUP BY GROUPING SETS ((column1), (column2), ());
GROUPING SETS
GROUP BY GROUPING SETS ((a), (b), ()) एक single pass में a से, b से, और overall totals compute करता है।
CUBE (a, b) listed columns का हर combination generate करता है और ROLLUP एक hierarchy। एक grouping से belong न करने वाली rows में उस column में NULL है।
यह कई UNION ALL queries की जगह लेता है।
Note:
GROUPING SETS UNION ALL से joined कई GROUP BY queries की जगह लेता है।
उदाहरण: GROUPING SETS
shop=# SELECT region, item, SUM(qty) AS total
shop-# FROM sales GROUP BY GROUPING SETS ((region), (item), ())
shop-# ORDER BY region, item;
region | item | total
--------+------+-------
N | | 8
S | | 13
| book | 4
| lamp | 2
| pen | 15
| | 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. #}
आम गलतियां
- हर grouping के लिए separate queries लिखना
- NULL placeholder rows label न करना
- कई columns पर CUBE इस्तेमाल करना
चैप्टर सारांश
- एक query में कई groupings
- CUBE सारे combinations देता है
- ROLLUP एक hierarchy देता है
- Missing groups NULL दिखाती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: