diff --git a/P3/queries/query10.sql b/P3/queries/query10.sql index 85205c5..474fc44 100644 --- a/P3/queries/query10.sql +++ b/P3/queries/query10.sql @@ -4,7 +4,7 @@ -- Expected Heading: RELATION {province CHARACTER, country CHARACTER, qty_last10 INTEGER, qty_1020 INTEGER} -- How do you treat the default case as showed in the instructions? -SELECT province.name AS province, country.name AS country, qty_last10, (qty_last20-qty_last10) AS qty_1020 +SELECT province.name AS province, country.name AS country, qty_last10, qty_1020 FROM ( SELECT province, SUM(qty) as qty_last10 FROM Purchases @@ -12,13 +12,13 @@ FROM ( GROUP BY province ) AS L JOIN ( - SELECT province, SUM(qty) as qty_last20 + SELECT province, SUM(qty) as qty_1020 FROM Purchases - WHERE time > date((SELECT MAX(time) FROM Purchases),'-20 days') + WHERE time > date((SELECT MAX(time) FROM Purchases),'-20 days') AND time <= date((SELECT MAX(time) FROM Purchases),'-10 days') GROUP BY province ) AS P ON L.province = P.province JOIN province ON L.province = province.ROWID JOIN country ON province.country = country.code -ORDER BY (2*qty_last10-qty_last20) DESC +ORDER BY qty_last10-qty_1020 DESC LIMIT 10 ;