Reputation: 21288
I need to be able to show the items that has the top 10 highest values (quantity*price). In MySQL you can use LIMIT, but that's not possible in SQL Server. How can I achieve my goal?
Thanks in advance
SELECT ItemID, Itemname, Quantity, Price,
CONVERT(Decimal(8,0),ROUND((Quantity*price),2)) AS Total
FROM Item
Upvotes: 0
Views: 1251
Reputation: 5884
SELECT TOP 10 ItemID, ...
Maybe this will help you? Also look BOTTOM keyword.
Upvotes: 1
Reputation: 28247
SELECT TOP 10 ItemID, Itemname, Quantity, Price,
CONVERT(Decimal(8,0),ROUND((Quantity*price),2)) AS Total
FROM Item
ORDER BY Quantity * Price DESC
The ORDER BY Quantity * Price DESC
will ensure that the highest values are returned first.
Upvotes: 7
Reputation: 3097
SELECT TOP 10 TItemID, Itemname, Quantity, Price,
CONVERT(Decimal(8,0),ROUND((Quantity*price),2)) AS Total
FROM Item
ORDER BY Total DESC
Upvotes: 4