0
我想從3個不同的表中拉出數據,我的結果集並不是我期待的。正確的方式加入3表
SELECT mdp.ReportDate
, mdp.PolicyNumber
, Company
, StateCode
, LOB
, mdp.AccountReference
, EffectiveDate
, EquityDate
, AccountBalance
, TermPremium
, DelinquentAmount
, PolicyStatus
, dcbpt.PolicyTermExtendedData
, TermsInDays
, dcba.AccountId
FROM Bil_MonthlyDelinquentPayments mdp
INNER JOIN DC_BIL_Account AS dcba
ON PolicyNumber = dcba.AccountReference
AND ReportDate = (
SELECT Max(ReportDate)
FROM Bil_MonthlyDelinquentPayments maxmdp
WHERE Year(maxmdp.ReportDate) = 2017
AND Month(maxmdp.ReportDate) = 01
)
LEFT JOIN DC_BIL_PolicyTerm AS dcbpt
ON dcba.AccountId = dcbpt.PrimaryAccountId
AND PolicyTermEffectiveDate = (
SELECT Max(PolicyTermEffectiveDate)
FROM DC_BIL_PolicyTerm
)
ORDER BY AccountId
在我的結果集中,列dcbpt.PolicyTermExtendedData被返回爲空值。該列包含表中的數據,我期望我的結果集包含該數據,但不包含該數據。
如果您不提供足夠的信息,我們如何才能知道正確的查詢?向我們展示樣本數據和預期產出。 \t請閱讀[**如何提問**](http://stackoverflow.com/help/how-to-ask) \t \t這裏是一個偉大的地方[** START **] (http://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)來了解如何提高您的問題質量並獲得更好的答案。 –
在表中滿足條件「並且PolicyTermEffectiveDate = (SELECT Max(PolicyTermEffectiveDate) FROM DC_BIL_PolicyTerm)」在表DC_BTL_PolicyTerm中滿足條件「??? –
你知道['LEFT JOIN'](https://www.tutorialspoint.com/sql/sql-left-joins.htm)是如何工作的嗎? –