How to add a manual column based on GroupBy for title

  • Hello,

    I have a query to get data group by High, Medium and Low so only three rows will be returned.

    select

    sum(case .... ) then 1 else 0 end) as [Column1],

    sum(case .... ) then 1 else 0 end) as [Column2],

    sum(case .... ) then 1 else 0 end) as [Column3]

    from sometable

    Group by High, Medium, Low

    I want to manually add High, Medium and Low to each row's first column. the final result should look like:

    Column1 Column2 Column3

    High 123 123 123

    Medium 123 123 123

    Low 123 123 123

    How can I do it?

    Thank you very much.

  • Please provide table structure and sample data.

    Executive Junior Cowboy Developer, Esq.[/url]

  • Something like

    select

    case

    when <logical expression1 depending only on High, Medium, Low columns> then 'High'

    when <logical expression2 depending only on High, Medium, Low columns> then 'Medium'

    else 'Low' end as [ColHML],

    sum(case .... ) then 1 else 0 end) as [Column1],

    sum(case .... ) then 1 else 0 end) as [Column2],

    sum(case .... ) then 1 else 0 end) as [Column3]

    from sometable

    Group by High, Medium, Low

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

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