Fix P3/Q10

This commit is contained in:
Brieuc Dubois 2024-04-27 14:51:20 +02:00
parent 3165550234
commit 14dc4fe673
1 changed files with 4 additions and 4 deletions

View File

@ -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
;