В приведенном ниже примере мой запрос возвращает все столбцы NULL, что не является результатом, который я предполагал получить. Основываясь на предложении Where, условие 2019 должно было возвращать значения, а 2018 должно возвращать NULL
. Если одно OUTER JOIN завершилось неудачно, все другие объединения тоже не работают или я смотрю на это совершенно неправильно.
SELECT
SUM(MillForecastTons_NovDec_View.[11]) AS Nov,
SUM(MillForecastTons_NovDec_View.[12]) AS Dec,
SUM(MillForecastTons_View.[1]) AS Jan,
SUM(MillForecastTons_View.[2]) AS Feb,
SUM(MillForecastTons_View.[3]) AS Mar,
SUM(MillForecastTons_View.[4]) AS Apr,
SUM(MillForecastTons_View.[5]) AS May,
SUM(MillForecastTons_View.[6]) AS Jun,
SUM(MillForecastTons_View.[7]) AS Jul,
SUM(MillForecastTons_View.[8]) AS Aug,
SUM(MillForecastTons_View.[9]) AS Sep,
SUM(MillForecastTons_View.[10]) AS Oct,
SUM(MillForecastActTons_NovDec_View.[11]) AS NovAct,
SUM(MillForecastActTons_NovDec_View.[12]) AS DecAct,
SUM(MillForecastActTons_View.[1]) AS JanAct,
SUM(MillForecastActTons_View.[2]) AS FebAct,
SUM(MillForecastActTons_View.[3]) AS MarAct,
SUM(MillForecastActTons_View.[4]) AS AprAct,
SUM(MillForecastActTons_View.[5]) AS MayAct,
SUM(MillForecastActTons_View.[6]) AS JunAct,
SUM(MillForecastActTons_View.[7]) AS JulAct,
SUM(MillForecastActTons_View.[8]) AS AugAct,
SUM(MillForecastActTons_View.[9]) AS SepAct,
SUM(MillForecastActTons_View.[10]) AS OctAct,
SUM(MillForecastBudTons_NovDec_View.[11]) AS NovBud,
SUM(MillForecastBudTons_NovDec_View.[12]) AS DecBud,
SUM(MillForecastBudTons_View.[1]) AS JanBud,
SUM(MillForecastBudTons_View.[2]) AS FebBud,
SUM(MillForecastBudTons_View.[3]) AS MarBud,
SUM(MillForecastBudTons_View.[4]) AS AprBud,
SUM(MillForecastBudTons_View.[5]) AS MayBud,
SUM(MillForecastBudTons_View.[6]) AS JunBud,
SUM(MillForecastBudTons_View.[7]) AS JulBud,
SUM(MillForecastBudTons_View.[8]) AS AugBud,
SUM(MillForecastBudTons_View.[9]) AS SepBud,
SUM(MillForecastBudTons_View.[10]) AS OctBud
FROM MillForecast_View MillForecast_View
LEFT OUTER JOIN MillForecastBudTons_NovDec_View MillForecastBudTons_NovDec_View
ON MillForecast_View.MillForecastId = MillForecastBudTons_NovDec_View.MillForecastID
LEFT OUTER JOIN MillForecastTons_NovDec_View MillForecastTons_NovDec_View
ON MillForecast_View.MillForecastId = MillForecastTons_NovDec_View.MillForecastID
LEFT OUTER JOIN MillForecastActTons_NovDec_View MillForecastActTons_NovDec_View
ON MillForecast_View.MillForecastId = MillForecastActTons_NovDec_View.MillForecastID
LEFT OUTER JOIN MillForecastTons_View MillForecastTons_View
ON MillForecast_View.MillForecastId = MillForecastTons_View.MillForecastID
LEFT OUTER JOIN MillForecastActTons_View MillForecastActTons_View
ON MillForecast_View.MillForecastId = MillForecastActTons_View.MillForecastID
LEFT OUTER JOIN MillForecastBudTons_View MillForecastBudTons_View
ON MillForecast_View.MillForecastId = MillForecastBudTons_View.MillForecastID
WHERE MillForecastTons_View.Year = 2019 AND MillForecastActTons_View.Year = 2019 AND MillForecastBudTons_View.Year = 2019 AND MillForecastTons_NovDec_View.Year = 2019
AND MillForecastActTons_NovDec_View.Year = 2018 AND MillForecastBudTons_NovDec_View.Year = 2018