亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請教這個sql怎么寫?

請教這個sql怎么寫?

阿波羅的戰車 2018-07-20 11:23:25
現在商品item表結構item_id, title, product_id, type, price一個product下有多個商品,商品item有4種type(0,1,2,3),同一個type下可以有多個同樣type與同樣product_id的商品?,F在有N個商品id,我要根據這些商品id,來獲取這些商品的product_id,然后根據這些product_id再獲取item表里面,所有 product_id與4個type值組合下的一個price最低的商品 的列表。應該怎么寫sql?
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

select aa.* 
from item aa 
join (    select a.product_id,a.type,min(a.price) price 
    from item a 
    join (select product_id from item where item_id in (N) ) b
    on a.product_id=b.product_id    
    group by product_id,type) bb
    on aa.product_id=bb.product_id and aa.type=bb.type and aa.price=bb.price;


查看完整回答
反對 回復 2018-07-23
  • 1 回答
  • 0 關注
  • 654 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號