2

I need to write a SQL statement

  • if TC is greater than 1 return 500
  • if TC is greater than .5 return 200
  • if TC is greater than .25 return 100
  • if TC is less than .25 return 50.

I know it's a nested case, using MySQL

EDIT: If table two has columns Id, TC, how do I use above to update the TC value.

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
Merlin
  • 24,552
  • 41
  • 131
  • 206

1 Answers1

3
select case when tc > 1 then 500
            when tc > .5 then 200
            when tc > .25 then 100
            else 50
       end
    ...

EDIT: Based on comments from OP

update YourTable
    set tc = case when tc > 1 then 500
                 when tc > .5 then 200
                 when tc > .25 then 100
                 else 50
             end
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235