我要选择Max Price的TOP 2产品.
ProductID ProductName SupplierID CategoryID Unit Price
1 Chais 1 1 10 bags 18
2 Chang 1 1 24 bottles 19
3 Aniseed Syrup 1 2 12 bottles 10
Run Code Online (Sandbox Code Playgroud)
我用过:
Select TOP 2 *
from Products
where Price = (Select Max(Price) from Products);
Run Code Online (Sandbox Code Playgroud)
但结果只有一排.
小智 7
这将为您提供最高的2个最高价格,但如果相同的价格在那里两次,您将获得相同的值两次,但是从上面的代码中它将会这样做,假设这是您正在寻找的.
Select TOP 2 * from Products order by Price DESC
Run Code Online (Sandbox Code Playgroud)