Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Silberschatz, Korth and Sudarshan18.1Database System Concepts - 5 th Edition, Aug 26, 2005 Extended Aggregation in SQL:1999 The cube operation computes.

Similar presentations


Presentation on theme: "©Silberschatz, Korth and Sudarshan18.1Database System Concepts - 5 th Edition, Aug 26, 2005 Extended Aggregation in SQL:1999 The cube operation computes."— Presentation transcript:

1 ©Silberschatz, Korth and Sudarshan18.1Database System Concepts - 5 th Edition, Aug 26, 2005 Extended Aggregation in SQL:1999 The cube operation computes union of group by’s on every subset of the specified attributes E.g. consider the query select item-name, color, size, sum(number) from sales group by cube(item-name, color, size) This computes the union of eight different groupings of the sales relation: { (item-name, color, size), (item-name, color), (item-name, size), (color, size), (item-name), (color), (size), ( ) } where ( ) denotes an empty group by list. For each grouping, the result contains the null value for attributes not present in the grouping.

2 ©Silberschatz, Korth and Sudarshan18.2Database System Concepts - 5 th Edition, Aug 26, 2005 SQL Cube Example TypeStoreNumber DogMiami12 CatMiami18 TurtleTampa4 DogTampa14 CatNaples9 DogNaples5 TurtleNaples1 TypeStoreNumber CatMiami18 CatNaples9 CatNULL27 DogMiami12 DogTampa14 DogNaples5 DogNULL31 TurtleTampa4 TurtleNaples1 TurtleNULL5 Miami30 NULLNaples15 NULLTampa18 NULL 63 From: http://databases.about.com/od/sql/l/aacuberollup.htm SELECT Type, Store, SUM(Number) as Number FROM Pets GROUP BY CUBE(type,store) Generates summaries on (type, store), (type), (store), and ()

3 ©Silberschatz, Korth and Sudarshan18.3Database System Concepts - 5 th Edition, Aug 26, 2005 Extended Aggregation (Cont.) The rollup construct generates union on every prefix of specified list of attributes E.g. select item-name, color, size, sum(number) from sales group by rollup(item-name, color, size) Generates union of four groupings: { (item-name, color, size), (item-name, color), (item-name), ( ) } Rollup can be used to generate aggregates at multiple levels of a hierarchy.

4 ©Silberschatz, Korth and Sudarshan18.4Database System Concepts - 5 th Edition, Aug 26, 2005 SQL Rollup Example TypeStoreNumber DogMiami12 CatMiami18 TurtleTampa4 DogTampa14 CatNaples9 DogNaples5 TurtleNaples1 TypeStoreNumber CatMiami18 CatNaples9 CatNULL27 DogMiami12 DogTampa14 DogNaples5 DogNULL31 TurtleTampa4 TurtleNaples1 TurtleNULL5 63 From: http://databases.about.com/od/sql/l/aacuberollup.htm SELECT Type, Store, SUM(Number) as Number FROM Pets GROUP BY ROLLUP(type, store) Generates summaries on (type, store), (type), and ()


Download ppt "©Silberschatz, Korth and Sudarshan18.1Database System Concepts - 5 th Edition, Aug 26, 2005 Extended Aggregation in SQL:1999 The cube operation computes."

Similar presentations


Ads by Google