zoukankan      html  css  js  c++  java
  • MySQL中不允许使用列别名作为查询条件

    在MySQL中有个特殊的规定,即不允许使用列别名作为查询条件。比如有下面一个表:

    select
        ID,
        title,
        concept,
        conceptLength,
        addUserId,
        modifyTime
    from collections_wisdom

    将SQL修改如下:

    select
        ID+1 as newID,
        title,
        concept,
        conceptLength,
        addUserId,
        modifyTime
    from collections_wisdom
    where newID>2

    那么,执行起来就会出现异常:StatementCallback; bad SQL grammar

    实在要执行,只好把新字段的组成在条件里再实现一遍,如下:

    select
        ID+1 as newID,
        title,
        concept,
        conceptLength,
        addUserId,
        modifyTime
    from collections_wisdom
    where (ID+1)>2

    之所以MySQL中不允许使用列别名作为查询条件,据说是因为MySql中列的别名本来是返回结果的时候才显示的,不在SQL解析时候使用。在没有更令人信服的解释出现前,权且当做这样吧。

  • 相关阅读:
    PS
    div 解决高度塌陷
    gradle Error:Cause: unable to find valid certification path to requested target
    HTML
    前端路线图
    css 选择器
    css-day01
    Python图像处理 | 把图像中的白色变成透明
    X-Frame-Options(点击劫持)
    python两张图片显示在一张图上
  • 原文地址:https://www.cnblogs.com/heyang78/p/3333469.html
Copyright © 2011-2022 走看看