where条件中的Mysql别名 [英] Mysql alias in where condition

查看:64
本文介绍了where条件中的Mysql别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 SQL 代码:

This is my SQL CODE:

SELECT `qty`,`unitprice`, qty * unitprice as Stock FROM item where Stock<1000

但它说:

#1054 - 'where 子句'中的未知列'Stock'

#1054 - Unknown column 'Stock' in 'where clause'

如何解决?

推荐答案

列别名问题:

标准 SQL 不允许在 WHERE 子句中引用列别名.强加此限制是因为在评估 WHERE 子句时,可能尚未确定列值.

Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined.

您必须在 WHERE 子句中重复计算:

You must instead repeat the calculation within your WHERE clause:

SELECT qty, unitprice, qty * unitprice as Stock
FROM   item
WHERE  qty * unitprice < 1000

这篇关于where条件中的Mysql别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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