岁月如灬风
2019-11-05 16:36
采纳率: 76.9%
浏览 356
已采纳

oracle sql语句问题,帮忙看一下,谢谢了!!!

                 CASE
                  WHEN (select capgrade
                          from tb_tpost_userpost
                         where mpostid = i.mpostid
                           and spostid = i.spostid
                           and idcard = r.idcard) = 1 THEN
                   'Ⅰ级'
                  WHEN (select capgrade
                          from tb_tpost_userpost
                         where mpostid = i.mpostid
                           and spostid = i.spostid
                           and idcard = r.idcard) = 2 THEN
                   'Ⅱ级'
                  WHEN (select capgrade
                          from tb_tpost_userpost
                         where mpostid = i.mpostid
                           and spostid = i.spostid
                           and idcard = r.idcard) = 3 THEN
                   'Ⅲ级'
                  WHEN (select capgrade
                          from tb_tpost_userpost
                         where mpostid = i.mpostid
                           and spostid = i.spostid
                           and idcard = r.idcard) = 4 THEN
                   'Ⅳ级'
                  WHEN (select capgrade
                          from tb_tpost_userpost
                         where mpostid = i.mpostid
                           and spostid = i.spostid
                           and idcard = r.idcard) = 5 THEN
                   'Ⅴ级'
                  ELSE
                   '尚无等级'
                END usercapgrade 

语句太过长了,这个怎么改成外层嵌套一次查询,大佬帮忙看一下,谢谢

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • bj_0163_bj 2019-11-05 16:40
    已采纳

    为什么写成这样?不知道是不是你想要的
    select case when capgrade=1 then 'I级' when capgrade=2 then 'II级' when …… else '尚无等级' end usercapgrade
    from tb_tpost_userpost
    where mpostid = i.mpostid
    and spostid = i.spostid
    and idcard = r.idcard

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 浅析丶 2019-11-05 16:45

    把数字提取出来作为一个参数不就可以了嘛

    评论
    解决 无用
    打赏 举报
  • 宁内疚不迁就 2019-11-05 17:29

    创建一个临时表将重复的sql封装起来,直接用结果不就行了

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题