我有一张叫“预订”的桌子
> id status
1 P
2 P
另一个叫做“呼叫”
id calldate type booking
1 01/01/2012 DEL 1
2 01/02/2012 COL 1
3 01/03/2012 DEL 2
4 31/12/2019 COL 999
我想在 'bookings' ONCE 中列出每条记录,将来自 'call' 的相关记录显示为另一列,如下所示:
bookingId deliverydate collectiondate
1 01/01/2012 01/02/2012
2 01/03/2012 null
我试过了:
select `b`.`bookingid` AS `bookingid`,
`del`.`calldate` AS `Delivery`,
`col`.`calldate` AS `Collection`
from `booking` `b`
left join `call` `del` on `b`.`bookingid` = `del`.`booking`
left join `call` `col` on `b`.`bookingid` = `col`.`booking`
where ((`del`.`type` = 'DEL') OR (`col`.`type` = 'COL') and (`b`.`status` = 'P'));
但我将 bookingid 1 列出 3 次。有人可以修复我的加入吗?