Query 1,2,5
This commit is contained in:
parent
63d9f90374
commit
30bc26ee02
|
@ -1,17 +1,12 @@
|
|||
-- Author: Anatole Huet
|
||||
|
||||
-- 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
|
||||
SELECT Country.name, COUNT(Purchases.id) as cnt
|
||||
FROM Purchases
|
||||
JOIN Province ON Purchases.province = Province.rowid
|
||||
JOIN Country ON Province.country = Country.code
|
||||
GROUP BY Country.name
|
||||
ORDER BY cnt DESC
|
||||
LIMIT 10
|
||||
;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-- Author: Anatole Huet
|
||||
|
||||
-- Determine the total number of purchases for each product. List the number of the product, as well as the total number of purchases.
|
||||
|
||||
SELECT product, sum(qty) as cnt
|
||||
SELECT product, Count(*) as cnt
|
||||
FROM Purchases
|
||||
GROUP BY product
|
||||
;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
-- Author: Anatole Huet
|
||||
|
||||
-- Determine the total number of purchases for each product. List the number of the product, as well as the total number of purchases.
|
||||
|
||||
SELECT product, Count(*) as cnt
|
||||
FROM Purchases
|
||||
where time > date((SELECT MAX(time) FROM Purchases),'-10 days')
|
||||
GROUP BY product
|
||||
;
|
Loading…
Reference in New Issue