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

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

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

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

        Mysql 或/和优先级?

        时间:2023-08-18

          <tbody id='Iv7zl'></tbody>
          <tfoot id='Iv7zl'></tfoot>

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

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

                <i id='Iv7zl'><tr id='Iv7zl'><dt id='Iv7zl'><q id='Iv7zl'><span id='Iv7zl'><b id='Iv7zl'><form id='Iv7zl'><ins id='Iv7zl'></ins><ul id='Iv7zl'></ul><sub id='Iv7zl'></sub></form><legend id='Iv7zl'></legend><bdo id='Iv7zl'><pre id='Iv7zl'><center id='Iv7zl'></center></pre></bdo></b><th id='Iv7zl'></th></span></q></dt></tr></i><div id='Iv7zl'><tfoot id='Iv7zl'></tfoot><dl id='Iv7zl'><fieldset id='Iv7zl'></fieldset></dl></div>
                • <bdo id='Iv7zl'></bdo><ul id='Iv7zl'></ul>
                  本文介绍了Mysql 或/和优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想知道 or/and 是如何工作的?

                  I am wondering how or/and works?

                  例如,如果我想获取 display = 1 的所有行

                  For example if I want to get all rows where display = 1

                  我只能做WHERE tablename.display = 1

                  如果我想要 display = 1 或 2 的所有行

                  and if I want all rows where display = 1 or 2

                  我可以做WHERE tablename.display = 1 or tablename.display = 2

                  但是,如果我想获取 display = 1 或 2 以及 任何 内容、标签或标题包含 hello world

                  But what if I want to get all rows where display = 1 or 2 and where any of the content, tags, or title contains hello world

                  这个逻辑将如何发挥作用?

                  How would the logic play out for that?

                  Select * from tablename 
                  where display = 1 or display = 2 and content like "%hello world%" or tags like "%hello world%" or title = "%hello world%"
                  

                  这是我的猜测.但我可以通过多种方式阅读.

                  Would be my guess. but then I can read that in several ways.

                  是否读出为:

                   (display = 1 or display = 2) and (content like "%hello world%" or tags like "%hello world%" or title = "%hello world%")
                  

                  或作为

                  ((display = 1 or display = 2) and (content like "%hello world%")) or (tags like "%hello world%" or title = "%hello world%")
                  

                  推荐答案

                  MySQL 文档有一个 良好页面,其中包含有关哪些运算符优先的信息.

                  The MySQL documentation has a good page with information on which operators take precedence.

                  从那个页面,

                  12.3.1.运算符优先级

                  12.3.1. Operator Precedence

                  运算符优先级如下表所示,从最高优先级到最低优先级.运营商一起显示在一行中具有相同的优先级.

                  Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.

                  INTERVAL
                  BINARY, COLLATE
                  !
                  - (unary minus), ~ (unary bit inversion)
                  ^
                  *, /, DIV, %, MOD
                  -, +
                  <<, >>
                  &
                  |
                  = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
                  BETWEEN, CASE, WHEN, THEN, ELSE
                  NOT
                  &&, AND
                  XOR
                  ||, OR
                  = (assignment), :=
                  

                  所以你的原始查询

                  Select
                      *
                  from tablename 
                  where
                      display = 1
                      or display = 2
                      and content like "%hello world%"
                      or tags like "%hello world%"
                      or title = "%hello world%"
                  

                  会被解释为

                  Select
                      *
                  from tablename 
                  where 
                      (display = 1)
                      or (
                          (display = 2)
                          and (content like "%hello world%")
                      )
                      or (tags like "%hello world%")
                      or (title = "%hello world%")
                  

                  如有疑问,请使用括号来明确您的意图.尽管 MySQL 页面上的信息很有帮助,但如果再次访问该查询,则可能不会立即显而易见.

                  When in doubt, use parenthesis to make your intent clear. While the information on the MySQL page is helpful, it may not be immediately obvious if the query is ever revisited.

                  您可能会考虑以下内容.请注意,我已将 title = "%hello world%" 更改为 title like "%hello world%",因为这更符合您描述的目标.

                  You might consider something like the following. Note that I've changed the title = "%hello world%" to title like "%hello world%", since that fits better with the goal you've described.

                  Select
                      *
                  from tablename 
                  where
                      (
                          (display = 1)
                          or (display = 2)
                      ) and (
                          (content like "%hello world%")
                          or (tags like "%hello world%")
                          or (title like "%hello world%")
                      )
                  

                  这篇关于Mysql 或/和优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:不同的数据库使用不同的名称引用吗? 下一篇:用一个命令截断 MySQL 数据库中的所有表?

                  相关文章

                  最新文章

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

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

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