Query 1,2,5

This commit is contained in:
Brieuc Dubois 2024-04-24 11:31:15 +02:00
parent 63d9f90374
commit 30bc26ee02
3 changed files with 21 additions and 15 deletions

View File

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

View File

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

9
P3/queries/query5.sql Normal file
View File

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