为什么该查询没有按我预期的那样工作? [英] Why that query isn't working as i expected ?

查看:38
本文介绍了为什么该查询没有按我预期的那样工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT 3 AS x, 5 as y, (x+y) as z

结果如我所愿;

x  y  z
3  5  8

我得到的结果;

#1054 - Unknown column 'x' in 'field list' 

推荐答案

SELECT 子句(和列别名)是同时计算的,没有特定的顺序.也就是说,在你想要 z 的同一点,x 和 y 列还不存在.

The SELECT clause (and column aliases) are evaluated at the same time and in no particular order. That is, at the same point you want z, the columns x and y do not exist yet.

SELECT
   (x+y) as z
FROM
    (
    SELECT 3 AS x, 5 as y
    ) t;

这篇关于为什么该查询没有按我预期的那样工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆