我有一个需要在 Sybase Adaptive Server Enterprise 中实现的长嵌套完全外部连接序列。是否可以为此编写一个函数?
我想简化下面的代码:
select t1.col_01, t1.col_02, TOT_Jan, TOT_Feb
from
(select a.col_01, a.col_02, sum(b.col_XX) as TOT_Jan
FROM vw_aux a ...
and year(b.tms_mydate) = 2012
and month(b.tms_mydate) = 1
... ) t1
left outer join
(select a.col_01, a.col_02, sum(b.col_XX) as TOT_Feb
... and year(b.tms_mydate) = 2012
and month(b.tms_mydate) = 2
... ) t2 on t1.col_aux = t2.col_aux
UNION
(select a.col_01, a.col_02, sum(b.col_XX) as TOT_Jan ...) t1
right outer join (select a.col_01, a.col_02, sum(b.col_XX) as TOT_Feb ...) t2
on ...
像这样创建一个函数:
funcion myfullouterjoin (vw_aux, table_01, col_aux, col_01, col_02, tms_mydate, TOT_Jan, TOT_Feb)