我正在將 xampp 與 mysql 一起使用,并且一直在嘗試格式化在 4 個單獨的表上使用內部聯接的查詢。內連接包含表 customer、bankaccounts、has 和 transactions。將銀行帳戶和客戶表從 M:N 鏈接到 1:M,而交易鏈接到銀行帳戶。我嘗試了以下查詢:
SELECT t.TransactionID,
t.Description,
t.Amount,
t.isLoan,
t.TransactionDate,
a.AccountID,
a.SortCode,
a.Name,
a.CreationDate,
c.FirstName,
c.LastName
c.DateofBirth
FROM transactions AS t
INNER JOIN bankaccounts AS a
#inner join 將通過組合選擇的值來創建一個新表,這些值是否滿足以下條件
ON t.TransactionID IN ( SELECT t.TransactionID
FROM transactions
WHERE t.TransactionDate BETWEEN '2021-11-25' AND '2021-12-01'
)
AND t.AccountID = a.AccountID
INNER JOIN has ON has.AccountID = a.AccountID ---- > #multiple inner joins can occur on multiple tables
INNER JOIN customers AS c ON has.CustomerID = c.CustomerID;
然而,這目前只給出一個錯誤。
我需要的是將所有表格鏈接在一起,同時確保只選擇這些特定日期之間的交易。
有沒有辦法解決這個問題?
uj5u.com熱心網友回復:
您應該將帶有子查詢的條件移動到WHERE子句:
SELECT t.TransactionID, t.Description, t.Amount, t.isLoan, t.TransactionDate,
a.AccountID, a.SortCode, a.Name, a.CreationDate,
c.FirstName, c.LastName, c.DateofBirth
FROM transactions AS t
INNER JOIN bankaccounts AS a ON t.AccountID = a.AccountID
INNER JOIN has ON has.AccountID = a.AccountID
INNER JOIN customers AS c ON has.CustomerID = c.CustomerID
WHERE t.TransactionDate BETWEEN '2021-11-25' AND '2021-12-01';
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/398122.html
標籤:mysql 加入 phpmyadmin xampp 玛丽亚数据库
上一篇:將文章的文本方向從左到右更改
