SlideShare une entreprise Scribd logo
1  sur  22
Enhancements to the GROUP BY Clause  http://ecomputernotes.com
Objectives  After completing this lesson, you should be able to do the following:  "  Use the   ROLLUP   operation to produce subtotal values  "  Use the   CUBE   operation to produce cross-  tabulation values  "  Use the   GROUPING   function to identify the row  values created by   ROLLUP   or   CUBE  "  Use   GROUPING SETS   to produce a single result set  http://ecomputernotes.com
Review of Group Functions  Group functions operate on sets of rows to give one  result per group.  SELECT  [ column ,]  group_function(column). . .  FRO M  table  [WHERE  condition ]  [GROUP BY  group_by_expression ]  [ORDER BY  column ];  Example:  SELECT AVG(salary), STDDEV(salary),  COUNT(commission_pct),MAX(hire_date)  FROM  employees  WHERE  job_id LIKE 'SA%';  http://ecomputernotes.com
Review of the   GROUP BY   Clause  Syntax:  SELECT  [ column ,]  group_function(column). . .  FRO M  table  [WHERE  condition ]  [GROUP BY  group_by_expression ]  [ORDER BY  column ];  Example:  SELECT  department_id, job_id, SUM(salary),  COUNT(employee_id)  FROM  employees  GROUP BY department_id, job_id ;  http://ecomputernotes.com
Review of the   HAVING   Clause  SELECT  [ column ,]  group_function(column)...  FRO M  table  [WHERE  condition ]  [GROUP BY  group_by_expression ]  [HAVING  having_expression ]  [ORDER BY  column ];  "  Use the   HAVING   clause to specify which groups  are to be displayed.  "Y ou further restrict the groups on the basis of a  limiting condition.  http://ecomputernotes.com
GROUP BY   with   ROLLUP   and  CUBE   Operators  "  Use   ROLLUP   or   CUBE   with   GROUP BY   to produce superaggregate rows by cross-referencing columns.  "  ROLLUP   grouping produces a results set containing the regular grouped rows and the  subtotal values.  "  CUBE   grouping produces a results set containing the rows from   ROLLUP   and cross-tabulation rows.  http://ecomputernotes.com
ROLLUP   Operator  SELECT  [ column ,]  group_function(column). . .  FRO M  table  [WHERE  condition ]  [GROUP BY  [ROLLUP]   group_by_expression ]  [HAVING  having_expression ];  [ORDER BY  column ];  "  ROLLUP   is an extension to the   GROUP BY   clause.  "  Use the   ROLLUP   operation to produce cumulative aggregates, such as subtotals.  http://ecomputernotes.com
ROLLUP   Operator Example  SELECT  department_id, job_id, SUM(salary) FROM  employees  WHERE  department_id < 60  GROUP BY ROLLUP(department_id, job_id);  http://ecomputernotes.com
CUBE   Operator  SELECT  [ column ,]  group_function(column)...  FRO M  table  [WHERE  condition ]  [GROUP BY  [CUBE]   group_by_expression ]  [HAVING  having_expression ]  [ORDER BY  column ];  &quot;  CUBE   is an extension to the   GROUP BY   clause.  &quot;  You can use the   CUBE   operator to produce cross- tabulation values with a single   SELECT   statement.  http://ecomputernotes.com
CUBE   Operator: Example  SELECT  department_id, job_id, SUM(salary) FROM  employees  WHERE  department_id < 60  GROUP BY CUBE (department_id, job_id) ;  2  4  http://ecomputernotes.com
GROUPING   Function  SELECT  [ column ,]  group_function(column) . ,  GROUPING(expr)  FRO M  table  [WHERE  condition ]  [GROUP BY [ROLLUP][CUBE]   group_by_expression ] [HAVING  having_expression ]  [ORDER BY   column ];  &quot;  The   GROUPING   function can be used with either the  CUBE   or   ROLLUP   operator.  &quot;U sing the  G ROUPING  f unction, you can find the  groups forming the subtotal in a row.  &quot;U sing the  G ROUPING  f unction, you can differentiate  stored   NULL   values from   NULL   values created by  ROLLUP   or   CUBE .  &quot;  The   GROUPING   function returns 0 or 1.  http://ecomputernotes.com
GROUPING   Function: Example  SELECT  department_id DEPTID, job_id JOB, SUM(salary),  GROUPING(department_id) GRP_DEPT, GROUPING(job_id) GRP_JOB  FROM  employees  WHERE  department_id < 50  GROUP BY ROLLUP(department_id, job_id);  2  3  http://ecomputernotes.com
GROUPING SETS  &quot;G ROUPING SETS  a re a further extension of the  GROUP BY   clause.  &quot;Y ou can use  G ROUPING SETS  t o define multiple  groupings in the same query.  &quot;T he Oracle Server computes all groupings specified  in the   GROUPING SETS   clause and combines the results of individual groupings with a   UNION ALL operation.  &quot;G rouping set efficiency:  Only one pass over the base table is required. There is no need to write complex UNION statements. The more elements the GROUPING SETS have, the greater the performance benefit.  http://ecomputernotes.com
http://ecomputernotes.com
GROUPING SETS: Example  SELECT  department_id, job_id,  manager_id,avg(salary)  FROM  employees  GROUP BY GROUPING SETS  ((department_id,job_id), (job_id,manager_id));  1  «  2  http://ecomputernotes.com
http://ecomputernotes.com
Composite Columns  &quot;A  composite column is a collection of columns  that are treated as a unit.  ROLLUP (a,  , d)  (b,c)  &quot;  To specify composite columns, use the   GROUP BY  clause to group columns within parentheses so  that the Oracle server treats them as a unit while computing   ROLLUP   or   CUBE   operations.  &quot;W hen used with  R OLLUP  o r  C UBE,  composite  columns would mean skipping aggregation across  certain levels.  http://ecomputernotes.com
http://ecomputernotes.com
Composite Columns: Example  SELECT  department_id, job_id, manager_id,  SUM(salary)  FROM  employees  GROUP BY ROLLUP( department_id,(job_id, manager_id));  «  http://ecomputernotes.com
i
Concatenated Groupings  &quot;C oncatenated groupings offer a concise way to  generate useful combinations of groupings.  &quot;T o specify concatenated grouping sets, you  separate multiple grouping sets,   ROLLUP , and  CUBE   operations with commas so that the Oracle Server combines them into a single   GROUP BY  clause.  &quot;T he result is a cross-product of groupings from  each grouping set.  GROUP BY GROUPING SETS(a, b), GROUPING SETS(c, d)
Concatenated Groupigs Example  SELECT  department_id, job_id, manager_id, SUM(salary)  FROM  employees  GROUP BY department_id,  ROLLUP(job_id),  CUBE(manager_id);  «  « «

Contenu connexe

Tendances (20)

Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 
Les02
Les02Les02
Les02
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Powerpointpresentation.c
Powerpointpresentation.cPowerpointpresentation.c
Powerpointpresentation.c
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Les10
Les10Les10
Les10
 
Decent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsDecent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivars
 
235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial
 
PrimeNG - Components para la Vida Real
PrimeNG - Components para la Vida RealPrimeNG - Components para la Vida Real
PrimeNG - Components para la Vida Real
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 
Arrays in php
Arrays in phpArrays in php
Arrays in php
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries
 
Columnrename
ColumnrenameColumnrename
Columnrename
 
Fat Arrow (ES6)
Fat Arrow (ES6)Fat Arrow (ES6)
Fat Arrow (ES6)
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Clauses
ClausesClauses
Clauses
 
Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oracle
 
Les09
Les09Les09
Les09
 

Similaire à e computer notes - Enhancements to the group by clause

e computer notes - Aggregating data using group functions
e computer notes -  Aggregating data using group functionse computer notes -  Aggregating data using group functions
e computer notes - Aggregating data using group functionsecomputernotes
 
Oracle Database Advanced Querying
Oracle Database Advanced QueryingOracle Database Advanced Querying
Oracle Database Advanced QueryingZohar Elkayam
 
e computer notes - Creating views
e computer notes - Creating viewse computer notes - Creating views
e computer notes - Creating viewsecomputernotes
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricksYanli Liu
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueriesecomputernotes
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsZohar Elkayam
 
Group by clause mod
Group by clause modGroup by clause mod
Group by clause modNitesh Singh
 
Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Zohar Elkayam
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 
Sql basics 2
Sql basics 2Sql basics 2
Sql basics 2rchakra
 
Sql server ___________session_10(group by clause)
Sql server  ___________session_10(group by clause)Sql server  ___________session_10(group by clause)
Sql server ___________session_10(group by clause)Ehtisham Ali
 

Similaire à e computer notes - Enhancements to the group by clause (20)

Les17
Les17Les17
Les17
 
e computer notes - Aggregating data using group functions
e computer notes -  Aggregating data using group functionse computer notes -  Aggregating data using group functions
e computer notes - Aggregating data using group functions
 
Oracle Database Advanced Querying
Oracle Database Advanced QueryingOracle Database Advanced Querying
Oracle Database Advanced Querying
 
e computer notes - Creating views
e computer notes - Creating viewse computer notes - Creating views
e computer notes - Creating views
 
Les04
Les04Les04
Les04
 
Les04
Les04Les04
Les04
 
Les05
Les05Les05
Les05
 
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
Group by clause mod
Group by clause modGroup by clause mod
Group by clause mod
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)
 
MySQL Pro
MySQL ProMySQL Pro
MySQL Pro
 
Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 
Sql basics 2
Sql basics 2Sql basics 2
Sql basics 2
 
Sql server ___________session_10(group by clause)
Sql server  ___________session_10(group by clause)Sql server  ___________session_10(group by clause)
Sql server ___________session_10(group by clause)
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 

Plus de ecomputernotes

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraintsecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functionsecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueriesecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objectsecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueriesecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functionsecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36ecomputernotes
 

Plus de ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 

Dernier

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 

Dernier (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

e computer notes - Enhancements to the group by clause

  • 1. Enhancements to the GROUP BY Clause http://ecomputernotes.com
  • 2. Objectives After completing this lesson, you should be able to do the following: &quot; Use the ROLLUP operation to produce subtotal values &quot; Use the CUBE operation to produce cross- tabulation values &quot; Use the GROUPING function to identify the row values created by ROLLUP or CUBE &quot; Use GROUPING SETS to produce a single result set http://ecomputernotes.com
  • 3. Review of Group Functions Group functions operate on sets of rows to give one result per group. SELECT [ column ,] group_function(column). . . FRO M table [WHERE condition ] [GROUP BY group_by_expression ] [ORDER BY column ]; Example: SELECT AVG(salary), STDDEV(salary), COUNT(commission_pct),MAX(hire_date) FROM employees WHERE job_id LIKE 'SA%'; http://ecomputernotes.com
  • 4. Review of the GROUP BY Clause Syntax: SELECT [ column ,] group_function(column). . . FRO M table [WHERE condition ] [GROUP BY group_by_expression ] [ORDER BY column ]; Example: SELECT department_id, job_id, SUM(salary), COUNT(employee_id) FROM employees GROUP BY department_id, job_id ; http://ecomputernotes.com
  • 5. Review of the HAVING Clause SELECT [ column ,] group_function(column)... FRO M table [WHERE condition ] [GROUP BY group_by_expression ] [HAVING having_expression ] [ORDER BY column ]; &quot; Use the HAVING clause to specify which groups are to be displayed. &quot;Y ou further restrict the groups on the basis of a limiting condition. http://ecomputernotes.com
  • 6. GROUP BY with ROLLUP and CUBE Operators &quot; Use ROLLUP or CUBE with GROUP BY to produce superaggregate rows by cross-referencing columns. &quot; ROLLUP grouping produces a results set containing the regular grouped rows and the subtotal values. &quot; CUBE grouping produces a results set containing the rows from ROLLUP and cross-tabulation rows. http://ecomputernotes.com
  • 7. ROLLUP Operator SELECT [ column ,] group_function(column). . . FRO M table [WHERE condition ] [GROUP BY [ROLLUP] group_by_expression ] [HAVING having_expression ]; [ORDER BY column ]; &quot; ROLLUP is an extension to the GROUP BY clause. &quot; Use the ROLLUP operation to produce cumulative aggregates, such as subtotals. http://ecomputernotes.com
  • 8. ROLLUP Operator Example SELECT department_id, job_id, SUM(salary) FROM employees WHERE department_id < 60 GROUP BY ROLLUP(department_id, job_id); http://ecomputernotes.com
  • 9. CUBE Operator SELECT [ column ,] group_function(column)... FRO M table [WHERE condition ] [GROUP BY [CUBE] group_by_expression ] [HAVING having_expression ] [ORDER BY column ]; &quot; CUBE is an extension to the GROUP BY clause. &quot; You can use the CUBE operator to produce cross- tabulation values with a single SELECT statement. http://ecomputernotes.com
  • 10. CUBE Operator: Example SELECT department_id, job_id, SUM(salary) FROM employees WHERE department_id < 60 GROUP BY CUBE (department_id, job_id) ; 2 4 http://ecomputernotes.com
  • 11. GROUPING Function SELECT [ column ,] group_function(column) . , GROUPING(expr) FRO M table [WHERE condition ] [GROUP BY [ROLLUP][CUBE] group_by_expression ] [HAVING having_expression ] [ORDER BY column ]; &quot; The GROUPING function can be used with either the CUBE or ROLLUP operator. &quot;U sing the G ROUPING f unction, you can find the groups forming the subtotal in a row. &quot;U sing the G ROUPING f unction, you can differentiate stored NULL values from NULL values created by ROLLUP or CUBE . &quot; The GROUPING function returns 0 or 1. http://ecomputernotes.com
  • 12. GROUPING Function: Example SELECT department_id DEPTID, job_id JOB, SUM(salary), GROUPING(department_id) GRP_DEPT, GROUPING(job_id) GRP_JOB FROM employees WHERE department_id < 50 GROUP BY ROLLUP(department_id, job_id); 2 3 http://ecomputernotes.com
  • 13. GROUPING SETS &quot;G ROUPING SETS a re a further extension of the GROUP BY clause. &quot;Y ou can use G ROUPING SETS t o define multiple groupings in the same query. &quot;T he Oracle Server computes all groupings specified in the GROUPING SETS clause and combines the results of individual groupings with a UNION ALL operation. &quot;G rouping set efficiency: Only one pass over the base table is required. There is no need to write complex UNION statements. The more elements the GROUPING SETS have, the greater the performance benefit. http://ecomputernotes.com
  • 15. GROUPING SETS: Example SELECT department_id, job_id, manager_id,avg(salary) FROM employees GROUP BY GROUPING SETS ((department_id,job_id), (job_id,manager_id)); 1 « 2 http://ecomputernotes.com
  • 17. Composite Columns &quot;A composite column is a collection of columns that are treated as a unit. ROLLUP (a, , d) (b,c) &quot; To specify composite columns, use the GROUP BY clause to group columns within parentheses so that the Oracle server treats them as a unit while computing ROLLUP or CUBE operations. &quot;W hen used with R OLLUP o r C UBE, composite columns would mean skipping aggregation across certain levels. http://ecomputernotes.com
  • 19. Composite Columns: Example SELECT department_id, job_id, manager_id, SUM(salary) FROM employees GROUP BY ROLLUP( department_id,(job_id, manager_id)); « http://ecomputernotes.com
  • 20. i
  • 21. Concatenated Groupings &quot;C oncatenated groupings offer a concise way to generate useful combinations of groupings. &quot;T o specify concatenated grouping sets, you separate multiple grouping sets, ROLLUP , and CUBE operations with commas so that the Oracle Server combines them into a single GROUP BY clause. &quot;T he result is a cross-product of groupings from each grouping set. GROUP BY GROUPING SETS(a, b), GROUPING SETS(c, d)
  • 22. Concatenated Groupigs Example SELECT department_id, job_id, manager_id, SUM(salary) FROM employees GROUP BY department_id, ROLLUP(job_id), CUBE(manager_id); « « «