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

      <legend id='rSkMZ'><style id='rSkMZ'><dir id='rSkMZ'><q id='rSkMZ'></q></dir></style></legend>
    1. <tfoot id='rSkMZ'></tfoot>
      1. <small id='rSkMZ'></small><noframes id='rSkMZ'>

        你可以在 mysql 的 WHERE 子句中使用别名吗?

        时间:2023-08-19
        1. <i id='qylup'><tr id='qylup'><dt id='qylup'><q id='qylup'><span id='qylup'><b id='qylup'><form id='qylup'><ins id='qylup'></ins><ul id='qylup'></ul><sub id='qylup'></sub></form><legend id='qylup'></legend><bdo id='qylup'><pre id='qylup'><center id='qylup'></center></pre></bdo></b><th id='qylup'></th></span></q></dt></tr></i><div id='qylup'><tfoot id='qylup'></tfoot><dl id='qylup'><fieldset id='qylup'></fieldset></dl></div>

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

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

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

                  本文介绍了你可以在 mysql 的 WHERE 子句中使用别名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要在 WHERE 子句中使用别名,但它一直告诉我它是一个未知列.有没有办法解决这个问题?我需要选择评分高于 x 的记录.评分计算为以下别名:

                  I need to use an alias in the WHERE clause, but It keeps telling me that its an unknown column. Is there any way to get around this issue? I need to select records that have a rating higher than x. Rating is calculated as the following alias:

                  sum(reviews.rev_rating)/count(reviews.rev_id) as avg_rating
                  

                  推荐答案

                  您可以使用 HAVING 子句,可以看到别名,例如

                  You could use a HAVING clause, which can see the aliases, e.g.

                   HAVING avg_rating>5
                  

                  但是在 where 子句中,您需要重复您的表达式,例如

                  but in a where clause you'll need to repeat your expression, e.g.

                   WHERE (sum(reviews.rev_rating)/count(reviews.rev_id))>5
                  

                  但是!并非所有表达式都被允许 - 使用 SUM 之类的聚合函数将不起作用,在这种情况下,您需要使用 HAVING 子句.

                  BUT! Not all expressions will be allowed - using an aggregating function like SUM will not work, in which case you'll need to use a HAVING clause.

                  来自 MySQL 手册:

                  不允许引用WHERE 子句中的列别名,因为列值可能还没有当 WHERE 子句被确定被执行.参见 B.1.5.4 节,列别名问题".

                  It is not allowable to refer to a column alias in a WHERE clause, because the column value might not yet be determined when the WHERE clause is executed. See Section B.1.5.4, "Problems with Column Aliases".

                  这篇关于你可以在 mysql 的 WHERE 子句中使用别名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何让 MySQL 正确处理 UTF-8 下一篇:如何在 MySQL 中使用命令行导入 SQL 文件?

                  相关文章

                  最新文章

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

                    <legend id='xSqEF'><style id='xSqEF'><dir id='xSqEF'><q id='xSqEF'></q></dir></style></legend>
                      <bdo id='xSqEF'></bdo><ul id='xSqEF'></ul>

                    1. <tfoot id='xSqEF'></tfoot>