如何在 MySQL 中为字段或列设置别名? [英] How to alias a field or column in MySQL?

查看:45
本文介绍了如何在 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

这篇关于如何在 MySQL 中为字段或列设置别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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