gpt4 book ai didi

mysql - SQL 语法错误 near except

转载 作者:行者123 更新时间:2023-12-01 00:10:01 24 4
gpt4 key购买 nike

我正在尝试选择在城市的所有分支机构都拥有帐户的人。(使用 SQL 查询)

SELECT A.customId 
FROM accountholder as A
WHERE NOT EXISTS (
(SELECT name
FROM branch
WHERE city='LA')
EXCEPT (SELECT C.branch
FROM accountholder AS B, account AS C
WHERE B.accountnumber = C.accountnumber
AND A.customId = B.customId));

现在我得到了:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXCEPT (SELECT C.branch FROM accountholder AS B, account AS C WHERE B.accountnumber=' at line 1

而且我没有看到问题。我是瞎了还是傻了?

感谢您的帮助。

最佳答案

MySQL 不使用EXCEPT。使用 NOT IN .

SELECT A.customId 
FROM accountholder as A
WHERE branch NOT IN (
(SELECT name FROM branch WHERE city='LA')
AND branch NOT IN (SELECT C.branch FROM accountholder AS B, account AS C WHERE B.accountnumber = C.accountnumber AND A.customId = B.customId));

关于mysql - SQL 语法错误 near except,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27151155/

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