MySQL 重命名sql中的选择列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6911698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rename a select column in sql
提问by Jesh
I have a question about SQL. Here is the case: I have a table with 5 columns (C1...C5) I want to do
我有一个关于 SQL 的问题。情况如下:我有一个包含 5 列 (C1...C5) 的表格,我想做
select (C1+C2*3-C3*5/C4) from table;
Is there any way of naming the resulting column for referring later in a query ?
有没有办法命名结果列以供稍后在查询中引用?
回答by Jacob
SELECT (C1+C2*3-C3*5/C4) AS formula FROM table;
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.
您可以AS [alias]
在公式之后使用给它一个别名。以后是否可以使用它取决于您想在哪里使用它。如果你想在 where 子句中使用它,你必须将它包装在一个外部 select 中,因为 where 子句在你的别名之前被评估。
SELECT *
FROM (SELECT (C1+C2*3-C3*5/C4) AS formula FROM table) AS t1
WHERE formula > 100
回答by a'r
Yes, its called a column alias.
是的,它称为列别名。
select (C1+C2*3-C3*5/C4) AS result from table;
回答by Andrea
select (C1+C2*3-C3*5/C4) as new_name from table;