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
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
- [Answered ]-SetFont in ReportLab, Django
- [Answered ]-Invalid literal for int() with base 10: 'n'
- [Answered ]-Get main domain url without hardcoding
- [Answered ]-Django Model Form: show query form and handle post request for OneToMany fields
- [Answered ]-Django passing kwargs to inherited form causes error (generic UpdateView)
Source:stackexchange.com