- adapted from [DBCB] Example 20.19, pp. 1083-1085
- group dates by month and dealers by city:
INSERT INTO SalesV1
SELECT isbn, month, city, SUM(val) AS val, SUM(cnt) AS cnt
FROM Sales JOIN Dealers ON dealer = name
GROUP BY isbn, month, city;
- group dates by week and dealers by state
INSERT INTO SalesV2
SELECT isbn, week, state, SUM(val) AS val, SUM(cnt) AS cnt
FROM Sales JOIN Dealers ON dealer = name
GROUP BY isbn, week, state;
- these views can be used to answer queries that partition no
finer than either in any dimension
-
Q1: SELECT isbn, sum(val)
FROM Sales
GROUP BY isbn;
can be answered using SalesV1 or SalesV2, how?
-
Q2: SELECT isbn, year, state, sum(val)
FROM Sales JOIN Dealers ON dealer = name
GROUP BY isbn, year, state;
can be answered using only SalesV1 (how?), not SalesV2 (why?)
- state is not an attribute of SalesV1, only city
- cannot roll weeks into years
-
Q3: SELECT isbn, date, SUM(val)
FROM Sales
GROUP BY isbn, date;
can be answered by either SalesV1 or SalesV2
- month (of SalesV1) and week (of
SalesV2) are too coarse to recover days