diff --git a/P3/queries/query1.sql b/P3/queries/query1.sql index 7269bcc..502e21a 100644 --- a/P3/queries/query1.sql +++ b/P3/queries/query1.sql @@ -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 ; diff --git a/P3/queries/query2.sql b/P3/queries/query2.sql index 9712ef6..681f47b 100644 --- a/P3/queries/query2.sql +++ b/P3/queries/query2.sql @@ -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 ; diff --git a/P3/queries/query5.sql b/P3/queries/query5.sql new file mode 100644 index 0000000..d931907 --- /dev/null +++ b/P3/queries/query5.sql @@ -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 +;