选择嵌套案例

时间:2016-11-02 08:24:34

标签: sql oracle

我的错误在哪里?

select dr.ders_code, dr.year, 
case when dr.muf_sq is not null then 
case when (select muf_sq_id from mufredat_sq m  join ders_stud_ref dr on dr.muf_sq = m.muf_sq_id) = dr.muf_sq then dr.muf_sq end
end 
from ders_stud_ref dr

1 个答案:

答案 0 :(得分:1)

第一个错误是

select muf_sq_id 
                from mufredat_sq m  
                join ders_stud_ref dr on dr.muf_sq = m.muf_sq_id

可能会返回多行

我认为你需要像

这样的东西
select dr.ders_code, dr.year, 
case when dr.muf_sq is not null then 
case when exists (select muf_sq_id 
            from mufredat_sq m  
           where dr.muf_sq = m.muf_sq_id) then dr.muf_sq end
end 
from ders_stud_ref dr