I have a column in a table which can have 3 values - High, Medium , Low.
I want to display these on a web page with 3 checkboxes (High, Medium, Low) for each record in table, with the corresponding checkbox ticked based on the priority.
ID Priority
-----------
1 High
2 Low
3 High
4 Medium
I would like to write a SQL query that returns the following output
ID High Medium Low
---------------------
1 Y
2 Y
3 Y
4 Y
The approach I thought about is:
select
ID,
case
when priority = "High" then "Y"
else "N"
end as High,
case
when priority = "Medium" then "Y"
else "N"
end as Medium,
case
when priority = "Low" then "Y"
else "N"
end as Low;
This is a toy problem of what I am actually trying to achieve.
In my real project, I have 5-6 of such options which are different for each column and there are 4 such columns using this approach is making my query very long.
Here is a example of some columns and various values they might have
- Business growth - Growing , Stable , Decline , NA
- Frequency of Checks - Often , Sometimes , Never , NA
Please advice on a simpler more efficient solution.