日期:2014-05-17  浏览次数:20966 次

SQL语句里的值能不能暂时保存着,以便下面的值要用?
select t.value+t.value1 as v
from table t

比如上面的语句,我先要计算value+value1的和,然后下面又要用到这个和,再下面又要用到上面那个值的和。
不会只能下面重新累加上面的和吧?

------解决方案--------------------
SQL code
with t1 as (select 1+2 var1 from dual),
t2 as (select var1 from t1)

select var1 from t2;

-------------或者--------------------
with t1 as (select 1+2 var1 from dual),
t2 as (select (select var1 from t1) v1 from dual)

select v1 from t2;

------解决方案--------------------
select s.v m from (select t.yw_ly_id+t.yw_ly_id v from s_business_domain t) s
嵌套试试