我有这个查询,但我只想加入PostageRules
,PostageGroups
如果p.delivery
值为 -1
澄清一下,我只想要一个交付值,如果p.delivery
是 -1,那么我们需要从表中获取po.delivery
值。PostageRules
目前查询得到的po.delivery
值不管p.delivery
这可以在单个查询中实现吗?
SELECT
p.id as prod_id, p.delivery as delivery,
po.delivery AS delivery
FROM
products AS p
LEFT JOIN
PostageRules AS po ON p.shopkeeper = po.shopkeeper
LEFT JOIN
PostageGroups AS pg ON po.groupID = pg.id
AND po.minQty <= 1
AND po.maxQty >= 1
AND po.minPrice <= p.Price
AND po.maxPrice >= p.Price
AND po.minWeight <= p.weight
AND po.maxWeight >= p.weight
WHERE
(p.id = '32323')
ORDER BY
po.preference