• <i id='P91Ie'><tr id='P91Ie'><dt id='P91Ie'><q id='P91Ie'><span id='P91Ie'><b id='P91Ie'><form id='P91Ie'><ins id='P91Ie'></ins><ul id='P91Ie'></ul><sub id='P91Ie'></sub></form><legend id='P91Ie'></legend><bdo id='P91Ie'><pre id='P91Ie'><center id='P91Ie'></center></pre></bdo></b><th id='P91Ie'></th></span></q></dt></tr></i><div id='P91Ie'><tfoot id='P91Ie'></tfoot><dl id='P91Ie'><fieldset id='P91Ie'></fieldset></dl></div>

    <small id='P91Ie'></small><noframes id='P91Ie'>

  • <legend id='P91Ie'><style id='P91Ie'><dir id='P91Ie'><q id='P91Ie'></q></dir></style></legend>
  • <tfoot id='P91Ie'></tfoot>

          <bdo id='P91Ie'></bdo><ul id='P91Ie'></ul>

      1. MySQL 相当于 Oracle 中的 DECODE 函数

        MySQL equivalent of DECODE function in Oracle(MySQL 相当于 Oracle 中的 DECODE 函数)
          <bdo id='PrIAg'></bdo><ul id='PrIAg'></ul>

          • <legend id='PrIAg'><style id='PrIAg'><dir id='PrIAg'><q id='PrIAg'></q></dir></style></legend>

          • <small id='PrIAg'></small><noframes id='PrIAg'>

          • <tfoot id='PrIAg'></tfoot>

              <i id='PrIAg'><tr id='PrIAg'><dt id='PrIAg'><q id='PrIAg'><span id='PrIAg'><b id='PrIAg'><form id='PrIAg'><ins id='PrIAg'></ins><ul id='PrIAg'></ul><sub id='PrIAg'></sub></form><legend id='PrIAg'></legend><bdo id='PrIAg'><pre id='PrIAg'><center id='PrIAg'></center></pre></bdo></b><th id='PrIAg'></th></span></q></dt></tr></i><div id='PrIAg'><tfoot id='PrIAg'></tfoot><dl id='PrIAg'><fieldset id='PrIAg'></fieldset></dl></div>

                    <tbody id='PrIAg'></tbody>
                  本文介绍了MySQL 相当于 Oracle 中的 DECODE 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在 MySQL 中找到等效的 DECODE 函数.它是这样工作的:

                  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,'Fifteen',16,'Sixteen',
                         17,'Seventeen',18,'Eighteen',19,'Nineteen',
                         'Adult') AS AgeBracket
                  FROM Person
                  

                  DECODE 函数会将列 'Age' 的值与 13、14、15.. 进行比较,并返回适当的字符串值 'Thirteen'、'Fourteen'.. 如果没有匹配,则默认值为 'Adult'将被退回.

                  The DECODE function will compare value of column 'Age' with 13, 14, 15.. and return appropriate string value 'Thirteen', 'Fourteen'.. and if it matches with nothing, then default value of 'Adult' will be returned.

                  有什么想法可以在 MySQL 中的哪个函数中完成这项工作?谢谢.

                  Any ideas which function in MySQL can do this job? Thanks.

                  澄清:我同意使用 CASE 是实现预期结果的一种方式,但出于性能和其他原因,我更愿意寻找函数.

                  CLARIFICATION: I agree using CASE is one way of achieving desired result, but I am rather looking for a function because of performance and other reasons.

                  推荐答案

                  您可以使用 IF(),而在 Oracle 中您会使用 DECODE().

                  You can use IF() where in Oracle you would have used DECODE().

                  mysql> select if(emp_id=1,'X','Y') as test, emp_id from emps; 
                  

                  这篇关于MySQL 相当于 Oracle 中的 DECODE 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                1. <legend id='a3kjU'><style id='a3kjU'><dir id='a3kjU'><q id='a3kjU'></q></dir></style></legend>
                2. <tfoot id='a3kjU'></tfoot>

                    <bdo id='a3kjU'></bdo><ul id='a3kjU'></ul>
                    • <small id='a3kjU'></small><noframes id='a3kjU'>

                          <tbody id='a3kjU'></tbody>
                            <i id='a3kjU'><tr id='a3kjU'><dt id='a3kjU'><q id='a3kjU'><span id='a3kjU'><b id='a3kjU'><form id='a3kjU'><ins id='a3kjU'></ins><ul id='a3kjU'></ul><sub id='a3kjU'></sub></form><legend id='a3kjU'></legend><bdo id='a3kjU'><pre id='a3kjU'><center id='a3kjU'></center></pre></bdo></b><th id='a3kjU'></th></span></q></dt></tr></i><div id='a3kjU'><tfoot id='a3kjU'></tfoot><dl id='a3kjU'><fieldset id='a3kjU'></fieldset></dl></div>