重命名SQL中的选择列 [英] Rename a select column in sql

查看:134
本文介绍了重命名SQL中的选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SQL有疑问.就是这种情况: 我有一个5列的表格(C1 ... C5) 我想做

I have a question about SQL. Here is the case: I have a table with 5 columns (C1...C5) I want to do

 select (C1+C2*3-C3*5/C4) from table;

是否可以命名结果列以供以后在查询中引用?

Is there any way of naming the resulting column for referring later in a query ?

推荐答案

SELECT (C1+C2*3-C3*5/C4) AS formula FROM table;

您可以在公式后使用AS [alias]为其命名.以后是否可以使用取决于您要在哪里使用.如果要在where子句中使用它,则必须将其包装在外部select中,因为where子句是在别名之前求值的.

You can give it an alias using AS [alias] after the formula. If you can use it later depends on where you want to use it. If you want to use it in the where clause, you have to wrap it in an outer select, because the where clause is evaluated before your alias.

SELECT * 
FROM (SELECT (C1+C2*3-C3*5/C4) AS formula FROM table) AS t1
WHERE formula > 100

这篇关于重命名SQL中的选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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