MySQL 中多个Left join 子查询
好久没写sql了,今天突然接到产品的需求,要拉取线上数据一个文章的统计,我心里就万马奔腾…TM,不是有前端埋点和事件埋点。。。
简单的联表查询
SELECT
a.id,
a.thumbNail,
a. NAME,
a.marketPrice,
a.memberPrice,
a.personName,
a. STATUS,
a.recieveOrderDate,
a.trackNumber,
a.contact,
a.reportSendDate,
b.trackNumber,
a.reportDownloadPath
FROM
(
SELECT
od.id,
ps.thumbNail,
ps. NAME,
od.marketPrice,
od.memberPrice,
od.personName,
od. STATUS,
od.recieveOrderDate,
ol.trackNumber,
ol.contact,
od.reportSendDate,
od.reportSendOrderLogisticId,
od.reportDownloadPath
FROM
orders.order_detail od
LEFT JOIN orders.order_logistics ol ON od.recieveOrderLogisticId = ol.id
LEFT JOIN orders.product_snapshot ps ON od.productSnapShotId = ps.id
WHERE
od.valid = TRUE
AND ol.valid = TRUE
AND od.orderId