SQL queries - TaaviGilden/The-Team GitHub Wiki

Query that returns the most popular product name, total quantity, unit price and unit price multiplied by the total quantity sold (most popular one is the one that gave highest income - last column max number)

SELECT TOP 1 name as Name, sum(quantity) as TotalQuantity,
itemprice as UnitPrice,
sum(itemprice * quantity) as Income
FROM "PUBLIC"."SOLDITEM"
GROUP BY name
ORDER BY Income DESC;

Query that returns the date with the highest income (should return only one row)

SELECT TOP 1
name, datetime, sum(total_price) as DayTotal
FROM "PUBLIC"."SOLDITEM" , "PUBLIC"."HISTORYITEM"
WHERE historyitem.id = solditem.id
GROUP BY datetime
ORDER BY DayTotal DESC;