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

    <legend id='NEJHy'><style id='NEJHy'><dir id='NEJHy'><q id='NEJHy'></q></dir></style></legend>
    • <bdo id='NEJHy'></bdo><ul id='NEJHy'></ul>
    <tfoot id='NEJHy'></tfoot>
    <i id='NEJHy'><tr id='NEJHy'><dt id='NEJHy'><q id='NEJHy'><span id='NEJHy'><b id='NEJHy'><form id='NEJHy'><ins id='NEJHy'></ins><ul id='NEJHy'></ul><sub id='NEJHy'></sub></form><legend id='NEJHy'></legend><bdo id='NEJHy'><pre id='NEJHy'><center id='NEJHy'></center></pre></bdo></b><th id='NEJHy'></th></span></q></dt></tr></i><div id='NEJHy'><tfoot id='NEJHy'></tfoot><dl id='NEJHy'><fieldset id='NEJHy'></fieldset></dl></div>
    1. MySQL - 在 WHERE 中选择 AS

      MySQL - SELECT AS in WHERE(MySQL - 在 WHERE 中选择 AS)

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

            <tbody id='ybnGC'></tbody>
        • <small id='ybnGC'></small><noframes id='ybnGC'>

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

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

                <i id='ybnGC'><tr id='ybnGC'><dt id='ybnGC'><q id='ybnGC'><span id='ybnGC'><b id='ybnGC'><form id='ybnGC'><ins id='ybnGC'></ins><ul id='ybnGC'></ul><sub id='ybnGC'></sub></form><legend id='ybnGC'></legend><bdo id='ybnGC'><pre id='ybnGC'><center id='ybnGC'></center></pre></bdo></b><th id='ybnGC'></th></span></q></dt></tr></i><div id='ybnGC'><tfoot id='ybnGC'></tfoot><dl id='ybnGC'><fieldset id='ybnGC'></fieldset></dl></div>
                本文介绍了MySQL - 在 WHERE 中选择 AS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                出于某种原因,这不起作用:

                For some reason, this doesn't work:

                select substring(rating, instr(rating,',') +1, +2) as val
                from users where val = '15';
                

                它给出了这个错误:

                错误 1054 (42S22):where 子句"中的未知列val"

                ERROR 1054 (42S22): Unknown column 'val' in 'where clause'

                那我该怎么做?

                推荐答案

                首先,您不能在 WHERE 子句上使用 ALIAS.您应该使用该列,

                First, you cannot use ALIAS on the WHERE clause. You shoul be using the column,

                SELECT SUBSTRING(rating, INSTR(rating,',') +1, +2) AS val 
                FROM   users 
                WHERE  SUBSTRING(rating, INSTR(rating,',') +1, +2) = '15'
                

                原因如下:操作顺序是SQL,

                The reason is as follows: the order of operation is SQL,

                • FROM 子句
                • WHERE 子句
                • GROUP BY 子句
                • HAVING 子句
                • SELECT 子句
                • ORDER BY 子句

                ALIAS 发生在 SELECT 子句上,它位于 WHERE 子句之前.

                the ALIAS takes place on the SELECT clause which is before the WHERE clause.

                如果你真的想使用别名,把它包装在一个子查询中,

                if you really want to use the alias, wrap it in a subquery,

                SELECT *
                FROM
                    (
                        SELECT SUBSTRING(rating, INSTR(rating,',') +1, +2) AS val 
                        FROM   users
                    ) s
                WHERE   val  = '15'
                

                这篇关于MySQL - 在 WHERE 中选择 AS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 查询中包含缺失的月份)
                  <tbody id='Roul3'></tbody>
                <legend id='Roul3'><style id='Roul3'><dir id='Roul3'><q id='Roul3'></q></dir></style></legend>
                  <tfoot id='Roul3'></tfoot>
                • <i id='Roul3'><tr id='Roul3'><dt id='Roul3'><q id='Roul3'><span id='Roul3'><b id='Roul3'><form id='Roul3'><ins id='Roul3'></ins><ul id='Roul3'></ul><sub id='Roul3'></sub></form><legend id='Roul3'></legend><bdo id='Roul3'><pre id='Roul3'><center id='Roul3'></center></pre></bdo></b><th id='Roul3'></th></span></q></dt></tr></i><div id='Roul3'><tfoot id='Roul3'></tfoot><dl id='Roul3'><fieldset id='Roul3'></fieldset></dl></div>

                      <bdo id='Roul3'></bdo><ul id='Roul3'></ul>
                      1. <small id='Roul3'></small><noframes id='Roul3'>