我正在尝试选择在城市的所有分支机构都拥有帐户的人。 (使用 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/