岁月如灬风 2019-11-05 16:36 采纳率: 0%
浏览 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?