可能重复:
SQL - find records from one table which don’t exist in another
我在MySQL中有以下(简化)架构:
箭头表示一个(非箭头侧)到多个(箭头侧)关系。
我想确定,对于哪个delivery_zone_weeks,客户没有每周订单。
答案 0 :(得分:0)
如果没有结构,样本数据和预期结果,很难完全理解,但似乎有点冒险你需要
SELECT * FROM DELIVERY_ZONE_WEEK WHERE ID_DELIVERY_ZONE_WEEK NOT IN
(SELECT WO.ID_DELIVERY_ZONE_WEEK FROM CUSTOMER C
JOIN SHIPPING_ADDRESS SA
ON C.ID_CUSTOMER = SA.ID_CUSTOMER
JOIN WEEKLY_ORDER WO
ON SA.ID_SHIPPING = WO.ID_SHIPPING
WHERE C.ID_CUSTOMER = @ID_CUSTOMER)