3 thoughts on “Advanced T-SQL Query Needed?”

  1. select (select count(*) from table where color=’Red’) Red, (Select count(*) from table where color=’Blue’) Blue, (Select count(*) from table where color=’Red’ or color=’Blue’) Total

  2. One-passage method:

    select sum(case when color=’Red’
    then Num else 0 end) [Number Red],
    sum(case when color=’Blue’
    then Num else 0 end) [Number Blue],
    sum(Num) [Total]
    from table_name

Leave a Reply to Serge M Cancel reply