sql加入一对多

时间:2017-09-01 11:20:37

标签: php sql

SELECT MONTH(cpo.taken_date) as month,
       year(cpo.taken_date) as year, 
       monthname(cpo.taken_date),
       cpo.taken_date,
       cpo.chkid, 
       cpo.chkoid ,
       ii.c_bid,
       SUM( CASE WHEN DATE(cpo.taken_date) >= '::start_date' AND DATE(cpo.taken_date) <= '::end_date' THEN COALESCE(cpo.payable_amount, 0) ELSE 0 END) AS total_payable_amount, 
       SUM(ci.quantity) AS total_quantity
FROM checkpoint_order cpo 
JOIN checkpoint_order_item ci ON (ci.chkoid = cpo.chkoid) 
JOIN item_item ii  ON (ci.iid=ii.iid)
WHERE DATE(cpo.taken_date) >= '::start_date'  AND DATE(cpo.taken_date) <= '::end_date'
GROUP by Month(cpo.taken_date)";

此处checkpoint_order_item包含多个item_item id。

如何加入这个?

0 个答案:

没有答案