advantages of sql include that it is easy to learn, non ... papers/ada/notes/lect_cb... ·...
TRANSCRIPT
![Page 1: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/1.jpg)
![Page 2: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/2.jpg)
Advantages of SQL include that it is easy to learn, non-procedural, free-
format,
DBMS-independent, and that it is a recognized international standard.
However, major limitation of SQL is the inability to answer routinely asked
business queries such as computing the percentage change in values between
this
month and a year ago or to compute moving averages, cumulative sums, and
other statistical functions.
![Page 3: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/3.jpg)
![Page 4: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/4.jpg)
SELECT location.region_code, SUM(cost)/1000000000 AS total_revenue
FROM sales, time,location
WHERE sales.time_code = time.time_code
AND sales.store_code = location.store_code
AND time.year = 2006
GROUP BY location.region_code
--you could constrain the regions you interested in by using the HAVING
clause.
HAVING LOCATION.REGION_CODE=‘NE’
OR location.region_code=‘NW’
![Page 5: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/5.jpg)
Aggregation is a fundamental part of OLAP. To improve aggregation capabilities
the SQL standard provides extensions to the GROUP BY clause such as the
ROLLUP and CUBE functions.
ROLLUP supports calculations using aggregations such as SUM, COUNT,
MAX, MIN, and AVG at increasing levels of aggregation, from the most detailed
up to a grand total. ROLLUP creates subtotals that roll up from the most detailed
level to a grand total, following a column list specified in the ROLLUP clause.
ROLLUP first calculates the standard aggregate values specified in the GROUP
BY clause and then creates progressively higher level subtotals, moving from
right to left through the column list until finally completing with a grand total.
ROLLUP creates subtotals at n + 1 levels, where n is the number of grouping
columns. For instance, if a query specifies ROLLUP on grouping columns of
store_name, , month, and description (product) (n = 3), the result set will include
rows at 4 aggregation levels.
![Page 6: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/6.jpg)
![Page 7: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/7.jpg)
![Page 8: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/8.jpg)
Group BY provides one level of aggregation based on the Group By columns
location.region _code and time.quarter
![Page 9: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/9.jpg)
![Page 10: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/10.jpg)
You will note there are additional rows known as super aggregate rows as they
further aggregate rows already aggregated by the values in each grouping
within the grouped table. The effect is to produce progressive subtotals
moving from right to left
GROUP BY ROLLUP clause equivalent to the OLAP operation of roll-ups
NOTE the use of NULLS to denote a super aggregate row
How do we differentiate a super aggregate row and an aggregate row where
the value of a grouping column is unknown and hence NULL? This can be
done using the grouping GROUPING function.
![Page 11: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/11.jpg)
![Page 12: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/12.jpg)
When the Grouping function takes a single argument, a column reference and
returns either a 0 or 1. When the grouping column identified by the argument
has a NULL value because the row is a super-aggregate row, the GROUPING
function returns 1 ELSE returns 0
![Page 13: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/13.jpg)
CUBE is similar to ROLLUP, enabling a single statement to calculate all
possible
combinations of aggregations. CUBE can generate the information needed in
cross-tabulation reports with a single query. CUBE is typically most suitable
in queries that use columns from multiple dimensions rather than columns
representing different levels of a single dimension.
CUBE generates all the subtotals that could be calculated for a data cube with
the specified dimensions.
CUBE can be used in any situation requiring cross-tabular reports. The data
needed for cross-tabular reports can be generated with a single SELECT using
CUBE. Like ROLLUP, CUBE can be helpful in generating summary tables.
However, CUBE can produce a heavy processing load. If you have n
grouping columns for CUBE, this will generate 2^n aggregate levels e.g. with
3 grouping columns, CUBE will generate 8 aggregation levels.
Partial Rollups and Cubes are also supported
GROUP BY location.region_code, ROLLUP(time.quarter)
GROUP BY location.region_code, CUBE(time.quarter)
Composite Columns
GROUP BY ROLLUP (time.year, (time.quarter, time.month),
time.day)
GROUP BY CUBE (time.year, (time.quarter, time.month), time.day)
![Page 14: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/14.jpg)
Generates additional super aggregate rows that are created for every
combination of the grouping columns
![Page 15: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/15.jpg)
The effect of the GROUP BY CUBE with n grouping columns is equivalent
To the OLAP operation of computing the lattice of cuboids for the n-D cube
![Page 16: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/16.jpg)
Cumulative and moving aggregates
SUM AVG MIN MAX, COUNT, VARIANCE, STDDEV,
FIRST_VALUE, LAST_VALUE
![Page 17: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/17.jpg)
The difference between RANK and DENSE_RANK is that DENSE_RANK
leaves no gaps in the sequential ranking sequence when there are ties for a
ranking.
![Page 18: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/18.jpg)
![Page 19: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/19.jpg)
![Page 20: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/20.jpg)
![Page 21: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/21.jpg)
![Page 22: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/22.jpg)
Windowing Calculations is another elementary OLAP Operator.
Can be used to compute cumulative, moving, and centered aggregates. They return a value for each row in the table, which depends on other rows in the corresponding window. These aggregate functions provide access to more than one row of a table without a self-join and can be used only in the SELECT and ORDER BY clauses of the query.
![Page 23: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/23.jpg)
![Page 24: Advantages of SQL include that it is easy to learn, non ... Papers/ADA/notes/lect_cb... · Advantages of SQL include that it is easy to learn, non-procedural, free-format, ... the](https://reader031.vdocuments.site/reader031/viewer/2022041621/5e3f28dc1cf3bf0ccf42b1d2/html5/thumbnails/24.jpg)