where clause on sum() function

  • select sum(col1) as c1 ,sum(col2) as c2 from table ...

    i want that sum(col1) may show where col3<>'' and sum(col2) may show col3='' or something else how can i prepare this query?

  • I am not sure I understand the question but this might be what you want:

    select

     sum(case when col3 <> '' then col1 else 0 end) as c1,

     sum(case when col3 = '' then col1 else 0 end) as c2

    from <table>

    this will sum every row with non-blank col3 into c1 and every row with blank col3 into c2.

  • hi,

    Thanks for reply. It is absolutely what i want. Thanks in advance again.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply