如何在case语句中使用join

时间:2016-01-12 11:47:46

标签: sql case

以下代码无效。我想拉出相应PACKAGE的BatchHorizo​​n。我无法直接使用"然后BatchHorizo​​n"因为batchhorizo​​n在子查询中。

Case When PACKAGE IN (SELECT DISTINCT PACKAGE
                      FROM BATCHINGWINDOW AS A
                     ) 
     Then (SELECT  BatchHorizon
           FROM BATCHINGWINDOW AS B 
           WHERE B.PACKAGE = A.PACKAGE
         )
     else 3
 end

1 个答案:

答案 0 :(得分:0)

select 

Case When O.PACKAGE IN (SELECT PACKAGE
                      FROM BATCHINGWINDOW  
                     ) 
     Then (SELECT  DISTINCT BatchHorizon
           FROM BATCHINGWINDOW AS B 
           WHERE B.PACKAGE = O.PACKAGE
         )
     else 3
 end pack
 from table O