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解析时候使用。在没有更令人信服的解释出现前,权且当做这样吧。

  • 相关阅读:
    移动端的头文件
    时间倒计时
    H5 判断应用是否打开或是下载
    创建 XMLHttpRequest 对象
    JS 发送POST
    总结题
    uploadify 插件,去了进度条
    PC 拖动 以百分比计算
    pc 拖动效果,拖动带范围
    spring.net 在demo中的分析
  • 原文地址:https://www.cnblogs.com/doudouxiaoye/p/5773749.html
Copyright © 2011-2022 走看看