Re: [SQL ] 組資料問題

作者: MOONY135 (談無慾)   2019-10-24 10:58:13
※ 引述《cutekid (可愛小孩子)》之銘言:
: 網址: http://sqlfiddle.com/#!9/920483/18
: select *
: from orders t1
: inner join order_items t2 on t1.id = t2.order_id
: inner join commodities t3 on t2.match_id = t3.id
: inner join (
: select t1.id,min(manufacture_time) as m_time
: from orders t1
: inner join order_items t2 on t1.id = t2.order_id
: inner join commodities t3 on t2.match_id = t3.id
我後來的想法是這樣
http://sqlfiddle.com/#!9/306fc6/4
把最小的manufacture_time JOIN 回order之後 就可以用兩個欄位來sort了
然後用orm查完之後再去組回傳資料

Links booklink

Contact Us: admin [ a t ] ucptt.com