我不知道該怎麼稱呼它,我試圖解釋它。MYSQL內部連接錯誤 - 'where子句'中的未知列'm.account_no'
我有兩個表:
1.會員
2. share_trx_history
一個成員可以有多個共享的記錄,我有以下結構 來顯示它(總借記卡,信用卡,平衡給定年份的開口)
+-----------+------+-------+--------+---------+--------+
|account_no | name | debit | credit | balance | opening|
+-----------+------+-------+--------+---------+--------+
我都試過,但它失敗:
SELECT m.account_no, m.name, share.*
FROM `member` AS m
INNER JOIN (
SELECT sth.account_no AS sth_account_no, SUM(sth.debit) AS sth_debit, SUM(sth.credit) AS sth_credit,(
SELECT sth2.balance
FROM `share_trx_history` AS sth2
WHERE sth2.account_no=m.account_no
ORDER BY sth2.share_issue_date ASC
LIMIT 0,1
) AS sth_balance,
(SELECT balance
FROM `share_trx_history` AS sth3
WHERE year(sth3.share_issue_date) <2014 AND sth3.account_no=m.account_no
ORDER BY sth3.share_issue_date DESC
LIMIT 0 , 1) AS sth_opening
FROM `share_trx_history` AS sth
WHERE sth.share_issue_date >= DATE_SUB(NOW(), INTERVAL 1 Year)
AND sth.account_no=m.account_no) AS share
ON share.sth_account_no = m.account_no
捐贈以下錯誤:
Unknown column 'm.account_no' in 'where clause'
有沒有簡單的方法來完成它?
我的查詢出了什麼問題?
謝謝
更新:
balance = (total debit + total dividend) - (total credit)
請檢查opening = previous year balance
你可以分享你的表結構,通過'http:/ /平方lfiddle.com /'? – ursitesion
好的我在sqlfiddle上分享它 –