gpt4 book ai didi

mysql - WHERE子句导致Mysql查询语法错误

转载 作者:行者123 更新时间:2023-11-30 00:28:31 24 4
gpt4 key购买 nike

考虑(银行的)表格:

账户

enter image description here

客户

enter image description here

我想返回所有拥有更多客户 ID 的客户不止一个银行账户

我的建议:

SELECT c.Client_id_number , c.firstName_client , c.lastName_Client , COUNT(a.Account_number) as number_of_accounts
FROM Clients AS c
LEFT JOIN Accounts AS a
ON a.Client_id_number = c.Client_id_number
GROUP BY Client_id_number
WHERE number_of_accounts >= 2;

但是 WHERE 子句会导致语法错误。为什么 ?

最佳答案

SELECT c.Client_id_number , c.firstName_client , c.lastName_Client , COUNT(a.Account_number) as number_of_accounts
FROM Clients AS c
LEFT JOIN Accounts AS a
ON a.Client_id_number = c.Client_id_number
GROUP BY Client_id_number
HAVING COUNT(a.Account_number) >= 2;

<强> See this for correct SQL clasues order

关于mysql - WHERE子句导致Mysql查询语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22688442/

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