sql case语句中的问题?

时间:2011-03-22 06:54:55

标签: plsql

     select no        
     from  shan      
     where  account_number      = '7111'
     and   area          = 'O1139'
     and   ty            = '1'
     and   ty1           = 'T'
     and   date          = '12-AUG-10'
     and   code          in (case 'B'
                             when 'B' then 'j01','j05'
                             when 'C' then 'j02','j06'
                             else 'j03'
                             end);

我需要检查'j01'或'j05'中的代码值,如何重写查询,请以正确的方式指导我?

1 个答案:

答案 0 :(得分:0)

select no from shan
where 
    account_number = '7111'
    and area          = 'O1139'
    and ty            = '1'
    and ty1           = 'T'
    and date          = '12-AUG-10'
    and ('B' = 'B' AND code in ('j01', 'j05') OR 'B' = 'C' AND code in ('j02','j06'))

仅适用于标量值。

提供的解决方案将是另一种选择。