How would you use grouping sets to produce the same results


Advanced SQL Assignment

I. 1. How would you use GROUPING SETS to produce the same results as the following GROUP BY CUBE?

SELECT state, productID, SUM(volume) FROM sales GROUP BY CUBE (state, productID) ORDER BY state, productID

2. How would you show the sub totals for each week, for each state, and for each product? (No other totals or grand totals are required.) Suppose the table structure is

TABLE sales (productID VARCHAR, state CHAR(2), week DATE, volume INT)

3. Discuss the utility of grouping and group_id functions

II. Describe below how this code will work:

SELECT dt, region, revenue,
count(*) OVER (twdw) AS moving_count,
avg(revenue) OVER (twdw) AS moving_average
FROM moving_average_data mad
WINDOW twdw AS (PARTITION BY region
ORDER BY dt RANGE BETWEEN
'7 days'::interval PRECEDING AND
'0 days'::interval FOLLOWING
ORDER BY region, dt

The response should include a reference list. Double-space, using Times New Roman 12 pnt font, one-inch margins, and APA style of writing and citations.

Solution Preview :

Prepared by a verified Expert
PL-SQL Programming: How would you use grouping sets to produce the same results
Reference No:- TGS03024381

Now Priced at $30 (50% Discount)

Recommended (99%)

Rated (4.3/5)