gpt4 book ai didi

mysql - 谁是在同一分行同时拥有账户和贷款的客户?

转载 作者:行者123 更新时间:2023-11-29 21:50:17 24 4
gpt4 key购买 nike

我有这些表: http://imgur.com/ylyXYZP

我想知道:在同一分行同时拥有账户和贷款的客户是谁?

我尝试了如下两段代码:

select distinct depositor.customer_name, account.branch_name
from (borrower inner join loan on borrower.loan_number=loan.loan_number)
inner join
( depositor inner join account on depositor.account_number=account.account_number )
on (account.branch_name=loan.branch_name and borrower.customer_name=depostior.customer_name);

还有这个:

select account.branch_name, depositor.customer branch_name
from account, depostior
where depositor.customer_name, account.branch_name
in ( borrower inner join loan on borrower.loan_number=loan.loan_number );

在最新的一个中,我以某种方式尝试了嵌套查询,但没有成功。

那么我该如何解决这个问题呢?谢谢

最佳答案

select distinct d.customer_name, a.branch_name
from depositor d, account a, borrower b, loan l
where
d.account_number = a.account_number
and d.customer_name = b.customer_name
and b.loan_number = l.loan_number
and l.branch_name = a.branch_name

用 INNER JOIN 语法重写

SELECT DISTINCT d.customer_name, a.branch_name
FROM depositor d
INNER JOIN account a ON d.account_number = a.account_number
INNER JOIN borrower b ON d.customer_name = b.customer_name
INNER JOIN loan l ON b.loan_number = l.loan_number
AND l.branch_name = a.branch_name

关于mysql - 谁是在同一分行同时拥有账户和贷款的客户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33714749/

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