Merlin
Merlin

Reputation: 25639

Nested case in Mysql

I need to write a SQL statement

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.

Upvotes: 2

Views: 575

Answers (1)

Joe Stefanelli
Joe Stefanelli

Reputation: 135818

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

Upvotes: 3

Related Questions