Skip to content
Advertisement

Obtain Name Column Based on Value

I have a table that calculates the number of associated records that fit a criteria for each parent record. See example below:

note – morning, afternoon and evening are only weekdays

What I am trying to achieve is to determine which columns have the lowest value and get their column name as such:

Here is my current SQL code to result in the first table:

Advertisement

Answer

You can use CASE/WHEN/ELSE to check for the specific conditions and produce different values. For example:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement