Sql 如何获取产品的唯一数据?

Sql 如何获取产品的唯一数据?,sql,Sql,我试过: SELECT DISTINCT product_id, realPriceBrutto FROM table WHERE quantity > 0 order by product_id, realPriceBrutto; ,但在我的结果中,对于某些id,我得到了3个不同的值( 195 - 39.68, 195 - 43.19...) 我需要产品id的最低realPriceBrutto值。 我也尝试过: select * from table where (product_i

我试过:

SELECT DISTINCT product_id, realPriceBrutto FROM table WHERE quantity > 0 order by product_id, realPriceBrutto;
,但在我的结果中,对于某些id,我得到了3个不同的值( 195 - 39.68, 195 - 43.19...) 我需要产品id的最低realPriceBrutto值。 我也尝试过:

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

您只需通过产品id对其进行分组,然后选择realPriceBrutto的min()

SELECT 
    product_id, min(realPriceBrutto)
FROM 
    table 
WHERE 
    quantity > 0 
group by
    product_id
order by 
    product_id