DEV Community

[Comment from a deleted post]
Collapse
 
buinauskas profile image
Evaldas Buinauskas • Edited

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.

Collapse
 
ytjchan profile image
ytjchan

Numbers like 3.995 would become low as well.

Collapse
 
sqlknowitall profile image
Jared Karney

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

 
ytjchan profile image
ytjchan

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