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.
|
-- 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
|
SELECT Country.name, COUNT(Purchases.id) as cnt
|
||||||
FROM (
|
FROM Purchases
|
||||||
SELECT country, sum(qty) as cnt
|
JOIN Province ON Purchases.province = Province.rowid
|
||||||
FROM (
|
JOIN Country ON Province.country = Country.code
|
||||||
SELECT province, sum(qty) as qty
|
GROUP BY Country.name
|
||||||
FROM Purchases
|
ORDER BY cnt DESC
|
||||||
GROUP BY province
|
LIMIT 10
|
||||||
)
|
|
||||||
JOIN province ON province = province.ROWID
|
|
||||||
GROUP BY country
|
|
||||||
ORDER BY cnt DESC
|
|
||||||
LIMIT 10
|
|
||||||
)
|
|
||||||
JOIN COUNTRY on country == code
|
|
||||||
;
|
;
|
||||||
|
|
|
@ -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.
|
-- 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
|
FROM Purchases
|
||||||
GROUP BY product
|
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