2013-09-23 101 views
-4

我的產品表,每條記錄都有它是在出售的價格,這可以改變SQL最大的產品價格

Product   Price 
a    2 
a    3 
a    4 
a    1 
b    10 
b    15 
b    20 

我想要一個查詢,這將給是最大的價格在其產品中是出售,價格最高在其產品b被出售,僅此而已

我有成千上萬的產品,這樣情況下,將不利於

回答

3

使用MAXGroup By

SELECT Product, MAX(Price) 
FROM YourTable 
GROUP BY Product 
+0

@JohnHenry - 沒問題 –

1
select product, max(price) as max_price 
from products 
group by product 
0

使用MAX功能和Group By關鍵字

SELECT Product, MAX(Price) FROM products GROUP BY Product