CS157b
Chris Pollett
May 8, 2023
Which of the following statements is true?
SELECT color, SUM(price) FROM Sales NATURAL JOIN Autos WHERE model = 'Gobi' GROUP BY color
('Gobi', 'red', '2011-05-21', 'Good Deal Joe', 30000, 2)which represents that dealer Good Deal Cars sold two red Gobi's on May 21, 2011 for a total of $30,000, would be in CUBE(Sales).
('Gobi', *, '2011-05-21', 'Good Deal Cars', 150000, 7)Indicating 7 sales totaling $150,000 on May 21, 2011 of Gobi's of any color at Good Deal Cars.
('Gobi', *, '2011-05-21', *, 2050000, 30)Indicating 30 sales totaling $2,050,000 on May 21, 2011 of Gobi's of any color at any dealer.
(*, *, *, *, 31067005, 210)Indicating 210 sales totaling $31,067,005 of any model in any color at any dealer for all time.
CREATE MATERIALIZED VIEW SalesCube AS SELECT model, color, date, dealer, SUM(val), SUM(cnt) FROM Sales GROUP BY model, color, date, dealer WITH CUBE;
('Gobi', NULL, '2011-05-21', 'Good Deal Cars', 150000, 7)
mysql> SELECT year, country, product, SUM(profit) AS profit FROM sales GROUP BY year ASC, country ASC, product ASC; +------+---------+------------+--------+ | year | country | product | profit | +------+---------+------------+--------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | | 2000 | USA | Calculator | 75 | | 2000 | USA | Computer | 1500 | | 2001 | Finland | Phone | 10 | | 2001 | USA | Calculator | 50 | | 2001 | USA | Computer | 2700 | | 2001 | USA | TV | 250 | +------+---------+------------+--------+Next with ROLLUP
mysql> SELECT year, country, product, SUM(profit) AS profit FROM sales GROUP BY year ASC, country ASC, product ASC WITH ROLLUP; +------+---------+------------+--------+ | year | country | product | profit | +------+---------+------------+--------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | Finland | NULL | 1600 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | | 2000 | India | NULL | 1350 | | 2000 | USA | Calculator | 75 | | 2000 | USA | Computer | 1500 | | 2000 | USA | NULL | 1575 | | 2000 | NULL | NULL | 4525 | | 2001 | Finland | Phone | 10 | | 2001 | Finland | NULL | 10 | | 2001 | USA | Calculator | 50 | | 2001 | USA | Computer | 2700 | | 2001 | USA | TV | 250 | | 2001 | USA | NULL | 3000 | | 2001 | NULL | NULL | 3010 | | NULL | NULL | NULL | 7535 | +------+---------+------------+--------+
SELECT I.item, J.item, COUNT(I.basket) FROM Baskets I, Baskets J WHERE I.basket = J.basket AND I.item < J.item GROUP BY I.item, J.item HAVING COUNT(I.basket) >= s;
INPUT: A file D consisting of baskets of items, a support threshold s, and a size limit q for the size of frequent itemsets. OUTPUT: The sets of itemsets F[1],F[2],..., F[q], where F[i] is the set of all itemsets of size i that appear in at least s baskets of D. METHOD: (1) LET C[1] = all items that appear in file D; (2) For n = 1 to q: (3) F[n] = those sets in C[n] that occur at least s times in D (4) IF n==q BREAK; (5) LET C[n+1] = all itemsets of S of size n+1 such that every subset S of size n is in F[n].