sql - Obtain an specific table -


i'm working sql server 2008 , built table function:

    select cod1 + cod2 + cod3 codfinal,            sum(case when sig1  =  'bco' 1 else 0 end) a1,            sum(case when sig1   = 'rip' 1 else 0 end) b1,            sum(case when sig1   = 'min' 1 else 0 end) b1,            sum(case when sig1   = 'mad' 1 else 0 end) b1,            sum(case when sig1   = 'cpr' 1 else 0 end) pc1,            sum(case when sig1   = 'mar' 1 else 0 end) b1,            sum(case when sig1   = 'lac' 1 else 0 end) clu dbo.database  

and obtained this:

codfinal   a1   b1  b1    b1   pc1   b1   clu  b12030     1    1   1      1     1    2    3 c12130     1    1   1      1     1    2    3 d12230     1    1   1      1     1    2    3 e12230     1    1   1      1     1    2    3 

but have table unique total value this:

codfinal   a1   b1  pc1  clu     b12030     1    5    1    3 c12130     1    5    1    3 d12230     1    5    1    3 e12230     1    5    1    3 

could this?

with mycodes ( select cod1 + cod2 + cod3 codfinal,            sum(case when sig1  =  'bco' 1 else 0 end) a1,            sum(case when sig1   = 'rip' 1 else 0 end) b1a,            sum(case when sig1   = 'min' 1 else 0 end) b1b,            sum(case when sig1   = 'mad' 1 else 0 end) b1c,            sum(case when sig1   = 'cpr' 1 else 0 end) pc1,            sum(case when sig1   = 'mar' 1 else 0 end) b1d,            sum(case when sig1   = 'lac' 1 else 0 end) clu dbo.database  ) select codfinal,a1,b1a+b1b+b1c+b1d b1, pc1,clu mycodes 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -