re: SQL 201: How to add IF-ELSE logic to SQL queries VIEW POST

FULL DISCUSSION
 

I think this query could be simplified.

select 
  game,
  global,
  case 
    when global >= 4.00 then 'high'
    when global > 2.00 and global <= 3.99 then 'mid'
    else 'low' end 
  as 'Sales Range'
from 
  sega_sales
SELECT 
  game,
  global,
  CASE 
    WHEN global >= 4.00 THEN 'high'
    WHEN global >  2.00 THEN 'mid'
    ELSE 'low'
  END AS [Sales Range]
FROM
  sega_sales

You don't really need to check if global is equal or less than 3.99 because you're already in another condition.

 

Numbers like 3.995 would become low as well.

 

No. 3.995 is not gte 4.00 so it moves to the next check. It IS greater than 2. So mid

I was pointing at the first snippet, which has two conditions to check for mid.

code of conduct - report abuse