2017-07-19 10 views
1

私が試してみました:商品の一意のデータを取得するにはどうすればよいですか?

SELECT DISTINCT product_id, realPriceBrutto FROM table WHERE quantity > 0 order by product_id, realPriceBrutto; 

を、私の結果に、私はいくつかのidの3つの異なる値( 195 43.19 ... - - 39.68、195)持っている私はのためのrealPriceBruttoの最小値を必要とする を製品番号。

select * from table 
where (product_id,realPriceBrutto) IN (select product_id,min(realPriceBrutto) from table group by product_id); 

答えて

2

あなたができるだけでgroup by PRODUCT_IDをし、realPriceBruttoの分を()選択: は、私も試してみました。

SELECT 
    product_id, min(realPriceBrutto) 
FROM 
    table 
WHERE 
    quantity > 0 
group by 
    product_id 
order by 
    product_id 
関連する問題