gpt4 book ai didi

mysql - 选择没有地址的客户

转载 作者:行者123 更新时间:2023-11-28 23:57:58 25 4
gpt4 key购买 nike

有两个表 ps_customer 和 ps_address。

ps_customer contains: id_customer and customer.email
ps_address contains: id_customer and few other fields.

我想选择 ps_address 表中不存在数据的客户。我正在使用 SQL 查询:

SELECT id_customer, customer.email FROM ps_customer 
WHERE id_customer NOT IN SELECT id_customer FROM ps_address;

但它会抛出错误,查询 SELECT id_customer FROM ps_address

最佳答案

您需要对这两个表进行 LEFT OUTER JOIN。

SELECT PSC.id_customer, PSCcustomer.email
FROM ps_customer PSC
LEFT OUTER JOIN ps_address PSA on PSC.id_customer = PSA.id_customer
WHERE PSA.id_customer IS NULL

关于mysql - 选择没有地址的客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30997768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com