MySQL equivalent of DECODE function in Oracle

后端 未结 8 2311
南方客
南方客 2020-11-29 09:26

I am trying to find an equivalent of DECODE function in MySQL. It works like this:

Select Name, DECODE(Age,
       13,\'Thirteen\',14,\'Fourteen\',15,\'Fifte         


        
相关标签:
8条回答
  • 2020-11-29 09:46

    you can use if() in place of decode() in mySql as follows This query will print all even id row.

    mysql> select id, name from employee where id in
    -> (select if(id%2=0,id,null) from employee);
    
    0 讨论(0)
  • 2020-11-29 09:48

    Try this:

    Select Name, ELT(Age-12,'Thirteen','Fourteen','Fifteen','Sixteen',
       'Seventeen','Eighteen','Nineteen','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult',
       'Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult','Adult') AS AgeBracket FROM Person
    
    0 讨论(0)
提交回复
热议问题