当前位置: 动力学知识库 > 问答 > 编程问答 >

Showing top 10 results in a table (SQL Server)

问题描述:

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

网友答案:
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.

网友答案:
SELECT TOP 10 TItemID, Itemname, Quantity, Price,
CONVERT(Decimal(8,0),ROUND((Quantity*price),2)) AS Total
FROM Item
ORDER BY Total DESC
网友答案:

You would use the TOP clause.

网友答案:
SELECT TOP 10 ItemID, ...

Maybe this will help you? Also look BOTTOM keyword.

分享给朋友:
您可能感兴趣的文章:
随机阅读: