CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: count

  1. #1
    Join Date
    Dec 2004
    Posts
    41

    count

    sql2000:

    Code:
    select table1.field1, table1.field2, case when table1.field5 = 10 then '10'
    when table.field5 = 11 then '11' end as result, table1.field6
    from table1
    is it possible to count number of times when result is '10'?.

  2. #2
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309

    Re: count

    Yes using a case wrapped by sum will make it work.

    select table1.column1, table1.column2, (case table1.column5 when 10 then '10'
    when 11 then '11' end) as result, table1.column6, sum(case when table1.column5 = 10 then 1 else 0 end) as count_ten
    from table1
    group by
    table1.column1, table1.column2, (case table1.column5 when 10 then '10'
    when 11 then '11' end), table1.column6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured