1
我一直在提高我的SQL知識,但仍未能理解如何創建一些查詢。從數據庫中選擇相關記錄
我有一個SQL Server數據庫中的以下表:
用戶(ID,姓名)
貸款(id_sender,id_receiver,金額,日期,date_payment)
什麼將是一個有效的查詢:
- 選擇已發送貸款的用戶的名稱s到另一個用戶無論是在2014年和2015年
- 選擇誰已將貸款彼此
任何建議都非常感謝用戶的對(ID1,ID2)!
編輯1:
我嘗試:
1.
SELECT name FROM User WHERE id IN (
SELECT id_sender FROM Loan WHERE
id_receiver IN (SELECT DISTINCT id_receiver WHERE YEAR(date) = 2014) AND
id_receiver IN (SELECT DISTINCT id_receiver WHERE YEAR(date) = 2015)
)
2.
SELECT id1, id2 FROM (
SELECT DISTINCT id_sender as id1 FROM Loan
WHERE id_receiver IN (
SELECT DISTINCT id_sender FROM Loan
WHERE id_receiver = ???
)
(?)
)
那你嘗試至今。添加您的疑問。我們會嘗試修復它 –
已添加它們。謝謝你的幫助! – shardl