作者MOONY135 (谈无慾)
看板Database
标题Re: [SQL ] 组资料问题
时间Thu Oct 24 10:58:13 2019
※ 引述《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查完之後再去组回传资料
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.34.35.125 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Database/M.1571885896.A.74E.html
※ 编辑: MOONY135 (114.34.35.125 台湾), 10/24/2019 11:07:58