Skip to content
annetts edited this page Nov 9, 2014 · 5 revisions

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 Quantity,
itemprice AS Price,
SUM(quantity*itemprice) AS Income
FROM solditem
GROUP BY name, itemprice
ORDER BY Income DESC;

Clone this wiki locally