SQL处理用户定义列的值

时间:2011-08-30 18:23:54

标签: sql

我可以这样做:

SELECT
   1 AS one,
   2 AS two,
   1 + 2 AS three;

但我想这样做:

SELECT
    1 AS one,
    2 AS two,
one + two AS three;

有可能吗?

2 个答案:

答案 0 :(得分:4)

你可以这样做:

SELECT one, two, (one+two) as three
FROM 
(
    SELECT 
         1 AS one 
         2 AS two
) t;

答案 1 :(得分:2)

方法是:

SELECT one, two, one + two AS 'three'
FROM (SELECT 1 as 'one', 2 as 'two') myTable