SQL 中 where 条件中 in 后面 加 CASE WHEN 语句 报错
selectnew_projectsize,count(cifno)from(selectdistinct(a.cifno)ascifno,b.new_projectsi...
select new_projectsize, count(cifno)
from (select distinct (a.cifno) as cifno,
b.new_projectsize as new_projectsize
from cr_xdall a, cr_corp_inf b
where substr(a.mon_date, 1, 6) = '201212'
and xdflag = '1'
and opn_br_no in
(case when '1' = '1' then
(select brno from poozfmessagebrno where upbrno = '56601') else
'50000' end)
and a.cifno = b.cifno
and bal != '0'
group by b.new_projectsize, a.cifno)
group by new_projectsize; 展开
from (select distinct (a.cifno) as cifno,
b.new_projectsize as new_projectsize
from cr_xdall a, cr_corp_inf b
where substr(a.mon_date, 1, 6) = '201212'
and xdflag = '1'
and opn_br_no in
(case when '1' = '1' then
(select brno from poozfmessagebrno where upbrno = '56601') else
'50000' end)
and a.cifno = b.cifno
and bal != '0'
group by b.new_projectsize, a.cifno)
group by new_projectsize; 展开
展开全部
case语句只能代表一个值,如果你的select brno from poozfmessagebrno where upbrno = '56601'语句中返回多个值的话就会报错喽
追问
我现在想要得到多个值,在in里做条件,该如何实现此方案
追答
那就看你为什么用case了,如果只是做选择的话,可以用if else写两组语句进行切换
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-01-29
展开全部
and opn_br_no in
(case when '1' = '1' then
(select brno from poozfmessagebrno where upbrno = '56601') else
'50000' end)
修改为:
and opn_br_no in
( select
case when '1' = '1' then brno else '50000' end
from
poozfmessagebrno
where upbrno = '56601'
)
(case when '1' = '1' then
(select brno from poozfmessagebrno where upbrno = '56601') else
'50000' end)
修改为:
and opn_br_no in
( select
case when '1' = '1' then brno else '50000' end
from
poozfmessagebrno
where upbrno = '56601'
)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先将select brno from poozfmessagebrno where upbrno = '56601'结果赋值给一个变量再去试一下语句
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询