user1854438 user1854438 - 2 years ago 126
SQL Question

SQL select max values

I have for example values 'X','Y','Z',' ' in column myValue

and want to do something like select max(myValue)

so I want one value, the one with the highest value where X=1, Y=2 and Z=0

Answer Source
select max(
    case myValue
        when 'X' then 1
        when 'Y' then 2
        when 'Z' then 0
    end) myValue
from myTable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download