2016-09-27 35 views

回答

1

如果我正確理解你的問題,你想是這樣的:

SELECT DISTINCT ON (product_id) product_id, sales 
FROM mytable 
ORDER BY product_id, sales; 
1

試試這個,

SELECT value,productid FROM 
table T1 
WHERE value=(select min(value) 
      from table t2 
      where t1.productid=t2.productid) 
0

不知道表結構,這是不可能正確地回答。不過,假設你orders表有一個order_id(PK),一個customer_idsales列,這應該這樣做:

select o1.product_id, o1.sales 
from orders o1 
where o1.sales <= all (select o2.sales 
         from orders o2 
         where o2.product_id = o1.product_id 
         and o2.order_id <> o1.order_id); 
相關問題