我在加入表和视图后创建视图。 该视图包含连接中的一些实际列,其中一些列是计算列(让我们称它们为type1)。其中一些是计算列(类型2)的计算。 有没有什么办法可以引用type1列来计算type2而不是再次编写整个代码? (我不想创建另一个子查询),只是检查是否有任何有效的方法来编写代码。这里不张贴实际的代码,这是我想要做的简称:编写查询的更好方法
Create view ABCD
col1,col2 , calc_col1, calc_col2 , Calc_col3
as
select a.col1 as col1 ,
a.col2 as col2,
case when some_calulations then 2 else 0 end as calc_col1,
(case when some_calulations then 2 else 0 end) - a.somecol as calc_col2 ,
((case when some_calulations then 2 else 0 end) - a.somecol) + 5)as calc_col3
from Table1 as a
left join view2 as b
on join_condition
你可以把它写在所需的值传递的“某些值的函数“但这似乎是低效的执行,但更容易维护。 – xQbert