linfo2172-databases/P3/queries/query1.sql

18 lines
445 B
SQL

-- Determine the 10 countries with the most purchases; list the names of these countries, as well as the number of purchases; sort the results in decreasing order of purchases.
SELECT name, cnt
FROM (
SELECT country, sum(qty) as cnt
FROM (
SELECT province, sum(qty) as qty
FROM Purchases
GROUP BY province
)
JOIN province ON province = province.ROWID
GROUP BY country
ORDER BY cnt DESC
LIMIT 10
)
JOIN COUNTRY on country == code
;