如何将当前在WHERE
子句中的联接移动AND subMainTable.ID = MainTable.ID
到FROM
子句中。
由于它的别名方式,我似乎无法将它移到那里。
这是一个有效的查询,我已重命名并删除了与该问题无关的部分。
SELECT
ID
,DETAILS
,ENTRYDATE
,ISNULL(LastBalance, 0) + (
SELECT SUM(VAL)
FROM tempData subMainTable
LEFT OUTER JOIN FinanceTable f ON subMainTable.ID = f.accId
AND subMainTable.TRANS_ID = f.txnID
WHERE subMainTable.TRANS_ID <= MainTable.TRANS_ID
AND subMainTable.ID = MainTable.ID
AND f.txnID IS NULL
) AS Balance
FROM
(SELECT MainTable.*
FROM tempData MainTable LEFT JOIN FinanceTable FinTable ON
(MainTable.ID = FinTable.accId
AND MainTable.TRANS_ID = FinTable.txnID )
WHERE (FinTable.accId IS NULL AND FinTable.txnID IS NULL )
) AS MainTable ...