pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-12-09 : 06:50:12
|
declare @test table(id int not null identity(1,1),phone int, one int, two int, three int, four int)insert @test(phone,one,two,three,four)select 11,0,-2,-3,0union allselect 111,-1,0,-1,0union allselect 222,-1,-2,0,-5union allselect 333,-1,-2,-3,0union allselect 444,-1,-2,-3,-4select *from @testid phone one two three four----------- ----------- ----------- ----------- ----------- -----------1 11 0 -2 -3 02 111 -1 0 -1 03 222 -1 -2 0 -54 333 -1 -2 -3 05 444 -1 -2 -3 -4if one timeone <0 thenm1=sum(one),m2=0,m3=0,m4=0if one timeone <0 and two <0 then m1=0,m2=sum(one+two),m3=0,m4=0if one timeone <0 and two <0 and three<0 then m1=0 ,m2=0, m3=sum(one+two+three),m4=0if one timeone <0 and two <0 and three<0 and four<0 then sum(one+two+three+four)How can I get so Results phone m1 m2 m3 m4 ----------- ----------- ------- --------- ----------- 111 -1 0 -1 0 222 0 -3 0 0 333 0 0 -6 0 444 0 0 0 -10http://sql-az.tr.gg/ |
|