如何在 MySQL 中为字段或列设置别名?

2021-11-20 00:00:00 alias subquery mysql

我正在尝试做这样的事情.但我收到一个未知的列错误:

I'm trying to do something like this. But I get an unknown column error:

SELECT SUM(field1 + field2) AS col1, col1 + field3 AS col3 from core

基本上,我只想使用别名,这样我就不需要执行之前执行的操作.这在mysql中可能吗?

Basically, I want to just use the alias so that I won't need to perform the operations performed earlier. Is this possible in mysql?

推荐答案

考虑使用子查询,例如:

Consider using a subquery, like:

SELECT col1
,      col1 + field3 AS col3 
FROM   (
       SELECT  field1 + field2 as col1
       ,       field3
       from    core
       ) as SubQueryAlias

相关文章