我正在尝试检索价格最高的产品:
SELECT ProductName, Price
FROM [Products]
ORDER BY Price DESC
LIMIT 1
我想知道是否有另一种方式以更高效的方式执行此操作,例如MAX。
答案 0 :(得分:1)
使用MAX和GROUP BY
SELECT ProductName, MAX(Price) [Price]
FROM [Products]
GROUP BY ProductName
ORDER BY MAX(Price) DESC
LIMIT 1;
答案 1 :(得分:0)
我总是用以下
完成它 SELECT top 1 Name
FROM tableName
按价格订购DESC
答案 2 :(得分:0)
select top 1 * from [Products] order by Price desc
答案 3 :(得分:0)
你可以使用TOP 1
,但你总是要考虑打平局的可能性,所以:
SELECT TOP 1 WITH TIES ProductName, Price
FROM [Products]
ORDER BY Price DESC