我的目标是生成生成独立总检查的代码。如下表所示:
column1 Column2 Column3 value independent total check
A B c1 10 Null
A B c2 11 Null
A B C_total 21 21
x y z1 10 Null
x y z2 20 Null
x y z_total 30 30
I am trying to employ a conditional sum, but with no success! What I have at the moment is:
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP Table #Temp
select t2.Column1, t2.Column2, t2.Column3,t2.value,
sum (case when (t2.column3 like '%_Total%' and t2.T_desk not like '%Total%') then t2.Value else Null end) over (partition by t2.Column2) as "independent_total_check"into #Temp from #sometemptable
这似乎没有正常工作?!如何对成分进行求和并生成小计?非常感谢你提前!