SELECT
oc.customer_id
,concat(oc.customer_fname,' ',oc.customer_lname) as Full_name
,oc.customer_email
,oc.customer_phone
,a.country
FROM online_customer oc
JOIN address a ON oc.address_id = a.address_id
WHERE oc.customer_id = (
SELECT
oh.customer_id
FROM order_header oh
WHERE oh.order_status = 'Cancelled'
)
GROUP BY oc.customer_id, concat(oc.customer_fname,' ', oc.customer_lname), oc.customer_email, oc.customer_phone, a.country;
order_header表中有一个名为Order_status的列,其值为“已发货”、“正在处理”和“已取消”。现在我需要一个在order_status中所有订单都为“Cancelled”的customer_id。我无法理解这个逻辑
1条答案
按热度按时间kwvwclae1#
您可以通过按
customer_id
对订单表进行分组,然后检查它只有一个不同的order_status
,并且该状态(使用max/min)为“Canceled”来实现此逻辑