2017-10-19 125 views
0

我們正在嘗試查找在同一分支中同時擁有貸款和帳戶的客戶的姓名。我們應該在這裏使用inner join嗎?到目前爲止,我們只寫了;使用內部連接查詢表?

select DISTINCT customer.name 
FROM Customer, Has_Loan, Branch, Has_Account 
WHERE 

enter image description here

我們已經嘗試了一些不同的東西沒有得到任何進一步的,所以感謝任何形式的幫助或提示:)

+0

今天提示:切換到現代,明確的'JOIN'語法。易於編寫(沒有錯誤),更易於閱讀(和維護),並且在需要時更容易轉換爲外部聯接。 – jarlh

+0

我無法閱讀那些微小的圖像文字。此外,這裏的大多數人都希望格式化文本,而不是圖像。 – jarlh

回答

1

你可以試試這個:

SELECT DISTINCT Customer.Name 
FROM Customer 
    INNER JOIN Has_Account ON Customer.Ssn = Has_Account.Assn 
    INNER JOIN Account ON Account.AccountNo = Has_Account.ANo 
    INNER JOIN Has_Loan ON Customer.Ssn = Has_Loan.Lssn 
    INNER JOIN Loan ON Loan.LoanNo = Has_Loan.LNo 
WHERE Loan.BranchID = Account.BranchID 
1
select c.name 
from customer c 
join has_loan hl on hl.lssn = c.ssn 
join loan l on hl.lno = l.loanno 
join has_account ha on ha.assn = c.ssn 
join account a on ha.ano = a.accountno 
join branch b on b.branchid = a.branchid 
where l.branchid = a.branchid 
group by c.name;