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

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

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

    1. <legend id='kp1j4'><style id='kp1j4'><dir id='kp1j4'><q id='kp1j4'></q></dir></style></legend>
    2. 在 MySQL 语句中使用 OR 到底有什么不同,带/不带括号?

      How exactly does using OR in a MySQL statement differ with/without parentheses?(在 MySQL 语句中使用 OR 到底有什么不同,带/不带括号?)

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

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

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

              • 本文介绍了在 MySQL 语句中使用 OR 到底有什么不同,带/不带括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有这个查询:

                SELECT * FROM (`users`) WHERE `date_next_payment` <= '2011-02-02' 
                    AND `status` = 'active' OR `status` = 'past due'
                

                这不会返回正确的结果.但是,在 OR 条件周围添加括号使其工作如下:

                Which does not return the correct results. However, adding parentheses around the OR conditions makes it work like so:

                SELECT * FROM (`users`) WHERE `date_next_payment` <= '2011-02-02'
                    AND (`status` = 'active' OR `status` = 'past due')
                

                我的问题是为什么不同?我知道这是在不带括号的情况下以不同的方式考虑 OR 语句;但我不明白这有什么不同.

                My question is why is it different? I understand that's is considering the OR statement differently without the parentheses; but I don't understand how it's different.

                我没有找到任何对此有帮助的文档.如果有任何链接,我将不胜感激.

                I haven't found any docs that have been helpful on this. If there's any links out there I'd really appreciate it.

                推荐答案

                这是因为 OR 具有较低的 运算符优先比 AND .每当数据库看到像

                This is because OR has lower operator precedence than AND. Whenever the DB sees an expression like

                A AND B OR C
                

                先评估AND,即它等价于

                the AND is evaluated first, i.e. it is equivalent to

                (A AND B) OR C
                

                所以如果你明确想要

                A AND (B OR C)
                

                相反,您必须放入括号.

                instead, you must put in the parentheses.

                顺便说一下,这不是 SQL 特有的.这些运算符的优先顺序在我知道的所有编程语言中都是相同的(即至少是 C、C++、C#、Java 和 Unix shell 脚本).

                This is btw not specific to SQL. The order of precedence of these operators is the same in all programming languages I know (i.e. at least C, C++, C#, Java and Unix shell scripts).

                这篇关于在 MySQL 语句中使用 OR 到底有什么不同,带/不带括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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. <tfoot id='RoOYV'></tfoot>

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

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