开发者

Rename a select column in sql

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

开发者_如何学JAVA
 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;

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


Yes, its called a column alias.

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜