已关闭,此问题需要details or clarity。目前不接受答复。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。
昨天关门了。
Improve this question
所以我快到了。脚本现在是这样的,2月份的Closing_balance为-457是不正确的。计算值应为(3575 + 1584)- 2041,即(1月期末余额+2月的Bikes_P_Mnth)-2月的值。有什么想法吗
以下是更新后的脚本和results.
的屏幕截图
enter code here
WITH CTE_closing_balance AS (
SELECT
[AssemblyType],
[Country],
[Bikes_P_Mth],
[Starting_Balance],
[Month],
[Values],
case
WHEN [AssemblyType] = 'Standard Assembly' AND [Country] = 'Zimbabwe' AND [Month] =
'January' THEN ([Starting_Balance] + [Bikes_P_Mth]) - [Values]
ELSE 0
END AS [Closing Balance]
FROM [dbo].[vw_ProductionAnalysis_Pivot]
),
CTE_closing_balance_final AS (
SELECT
[AssemblyType],
[Country],
[Bikes_P_Mth],
[Starting_Balance],
[Month],
[Values],
CASE
WHEN [AssemblyType] = 'Standard Assembly' AND [Country] = 'Zimbabwe' AND [Month] =
'January' THEN ([Starting_Balance] + [Bikes_P_Mth]) - [Values]
WHEN [AssemblyType] = 'Standard Assembly' AND [Country] = 'Zimbabwe' AND [Month] =
'February' THEN ([Closing Balance] + [Bikes_P_Mth]) - [Values]
ELSE 0
END AS Closing_Balance
FROM CTE_closing_balance
)
SELECT * FROM CTE_closing_balance_final;
1条答案
按热度按时间c8ib6hqw1#
试试这个: