debugging 病例陈述结果[已关闭]

nuypyhwy  于 2023-05-29  发布在  其他
关注(0)|答案(1)|浏览(148)

已关闭,此问题需要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;
c8ib6hqw

c8ib6hqw1#

试试这个:

WITH CTE_closing_balance AS (
  SELECT  
    [AssemblyType],
    [Country],
    [Assemblers],
    [Bikes_P_Assem],
    [Bikes_P_Day],
    [Bikes_P_Week],
    [Bikes_P_Mth],
    [Bikes_Per_Year_for_Period],
    [Temp_Mnths],
    [Balance],
    [Annual_Budget],
    [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],
    [Assemblers],
    [Bikes_P_Assem],
    [Bikes_P_Day],
    [Bikes_P_Week],
    [Bikes_P_Mth],
    [Bikes_Per_Year_for_Period],
    [Temp_Mnths],
    [Balance],
    [Annual_Budget],
    [Starting_Balance],
    [Month],
    [Values],
    CASE
      WHEN [AssemblyType] = 'Standard Assembly' AND [Country] = 'Zimbabwe' AND [Month] = 'February' THEN ([Closing Balance] + [Bikes_P_Mth]) - [Values]
      ELSE 0
    END AS Balance
  FROM CTE_closing_balance
)
SELECT * FROM CTE_closing_balance_final;

相关问题