1. <small id='zhrbb'></small><noframes id='zhrbb'>

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

      <legend id='zhrbb'><style id='zhrbb'><dir id='zhrbb'><q id='zhrbb'></q></dir></style></legend>
      <tfoot id='zhrbb'></tfoot>

      'SELECT' 语句中的 'IF' - 根据列值选择

      时间:2023-08-18
        • <bdo id='ynUpe'></bdo><ul id='ynUpe'></ul>
        • <small id='ynUpe'></small><noframes id='ynUpe'>

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

              <legend id='ynUpe'><style id='ynUpe'><dir id='ynUpe'><q id='ynUpe'></q></dir></style></legend>

                本文介绍了'SELECT' 语句中的 'IF' - 根据列值选择输出值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                SELECT id, amount FROM report
                

                如果 report.type='P'-amount 如果 <代码>report.type='N'.如何将其添加到上述查询中?

                I need amount to be amount if report.type='P' and -amount if report.type='N'. How do I add this to the above query?

                推荐答案

                SELECT id, 
                       IF(type = 'P', amount, amount * -1) as amount
                FROM report
                

                见http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html.

                此外,您可以在条件为空时进行处理.在金额为空的情况下:

                Additionally, you could handle when the condition is null. In the case of a null amount:

                SELECT id, 
                       IF(type = 'P', IFNULL(amount,0), IFNULL(amount,0) * -1) as amount
                FROM report
                

                IFNULL(amount,0)部分表示当金额不为空时返回金额,否则返回0.

                这篇关于'SELECT' 语句中的 'IF' - 根据列值选择输出值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 MySQL 中声明一个变量? 下一篇:MYSQL OR 与 IN 性能

                相关文章

                最新文章

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

                1. <small id='F09Zc'></small><noframes id='F09Zc'>

                  <tfoot id='F09Zc'></tfoot>

                    • <bdo id='F09Zc'></bdo><ul id='F09Zc'></ul>