[Answered ]-MySQL converting enum values to integer values

1👍

Use a CASE expression:

select sum(case enum_field
                when 'B' then -2
                when 'N' then -1
                when 'F' then 1
                when 'V' then 2   
           end) as total_sum
from your_table
👤Barmar

1👍

select sum(case when enum_field = 'B' then -2
                when enum_field = 'N' then -1
                when enum_field = 'F' then 1
                when enum_field = 'V' then 2   
           end) as total_sum
from your_table

Leave a comment