排序 order by

image.png

select (case

         when to_number(substr(a.signtime, 1, 2)) > 0 and

              to_number(substr(a.signtime, 1, 2)) <= 4 then

          '0-4点'

         when to_number(substr(a.signtime, 1, 2)) > 4 and

              to_number(substr(a.signtime, 1, 2)) <= 8 then

          '4-8点'

         when to_number(substr(a.signtime, 1, 2)) > 8 and

              to_number(substr(a.signtime, 1, 2)) <= 12 then

          '8-12点'

         when to_number(substr(a.signtime, 1, 2)) > 12 and

              to_number(substr(a.signtime, 1, 2)) <= 16 then

          '12-16点'

         when to_number(substr(a.signtime, 1, 2)) > 16 and

              to_number(substr(a.signtime, 1, 2)) <= 20 then

          '16-20点'

         when to_number(substr(a.signtime, 1, 2)) > 20 and

              to_number(substr(a.signtime, 1, 2)) <= 24 then

          '20-24点'

       end) as signtime,

       count(distinct a.contno) as 新单数量,

       sum(a.prem) / 10000 as 保费

  from lis_lcpol a

  left join com_bankcom b

    on a.agentcom = b.agentcom

 where a.operadatatype <> 'D'

   and a.prem <> 0

   and a.salechnl = '03'

   and b.deptname in ('${deptname}')

   and a.signdate >= date'2019-09-01'

and a.signdate <= date'2019-10-10' 

 group by (case

            when to_number(substr(a.signtime, 1, 2)) > 0 and

                 to_number(substr(a.signtime, 1, 2)) <= 4 then

             '0-4点'

            when to_number(substr(a.signtime, 1, 2)) > 4 and

                 to_number(substr(a.signtime, 1, 2)) <= 8 then

             '4-8点'

            when to_number(substr(a.signtime, 1, 2)) > 8 and

                 to_number(substr(a.signtime, 1, 2)) <= 12 then

             '8-12点'

            when to_number(substr(a.signtime, 1, 2)) > 12 and

                 to_number(substr(a.signtime, 1, 2)) <= 16 then

             '12-16点'

            when to_number(substr(a.signtime, 1, 2)) > 16 and

                 to_number(substr(a.signtime, 1, 2)) <= 20 then

             '16-20点'

            when to_number(substr(a.signtime, 1, 2)) > 20 and

                 to_number(substr(a.signtime, 1, 2)) <= 24 then

             '20-24点'

          end)

          order by (case

            when to_number(substr(a.signtime, 1, 2)) > 0 and

                 to_number(substr(a.signtime, 1, 2)) <= 4 then

             1

            when to_number(substr(a.signtime, 1, 2)) > 4 and

                 to_number(substr(a.signtime, 1, 2)) <= 8 then

             2

            when to_number(substr(a.signtime, 1, 2)) > 8 and

                 to_number(substr(a.signtime, 1, 2)) <= 12 then

             3

            when to_number(substr(a.signtime, 1, 2)) > 12 and

                 to_number(substr(a.signtime, 1, 2)) <= 16 then

             4

            when to_number(substr(a.signtime, 1, 2)) > 16 and

                 to_number(substr(a.signtime, 1, 2)) <= 20 then

             5

            when to_number(substr(a.signtime, 1, 2)) > 20 and

                 to_number(substr(a.signtime, 1, 2)) <= 24 then

             6

          end)

报错信息

image.png


image.png

FineReport free_zz 发布于 2019-11-1 10:21 (编辑于 2019-11-6 17:32)
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
axingLv6专家互助
发布于2019-11-1 11:20(编辑于 2019-11-1 14:03)
select (case

         when to_number(substr(a.signtime, 1, 2)) > 0 and

              to_number(substr(a.signtime, 1, 2)) <= 4 then

          '0-4点'

         when to_number(substr(a.signtime, 1, 2)) > 4 and

              to_number(substr(a.signtime, 1, 2)) <= 8 then

          '4-8点'

         when to_number(substr(a.signtime, 1, 2)) > 8 and

              to_number(substr(a.signtime, 1, 2)) <= 12 then

          '8-12点'

         when to_number(substr(a.signtime, 1, 2)) > 12 and

              to_number(substr(a.signtime, 1, 2)) <= 16 then

          '12-16点'

         when to_number(substr(a.signtime, 1, 2)) > 16 and

              to_number(substr(a.signtime, 1, 2)) <= 20 then

          '16-20点'

         when to_number(substr(a.signtime, 1, 2)) > 20 and

              to_number(substr(a.signtime, 1, 2)) <= 24 then

          '20-24点'

       end) as signtime,

       count(distinct a.contno) as 新单数量,

       sum(a.prem) / 10000 as 保费

  from lis_lcpol a

  left join com_bankcom b

    on a.agentcom = b.agentcom

 where a.operadatatype <> 'D'

   and a.prem <> 0

   and a.salechnl = '03'

   and b.deptname in ('${deptname}')

   and a.signdate >= date'2019-09-01'

	and a.signdate <= date'2019-10-10' 

 group by (case

            when to_number(substr(a.signtime, 1, 2)) > 0 and

                 to_number(substr(a.signtime, 1, 2)) <= 4 then

             '0-4点'

            when to_number(substr(a.signtime, 1, 2)) > 4 and

                 to_number(substr(a.signtime, 1, 2)) <= 8 then

             '4-8点'

            when to_number(substr(a.signtime, 1, 2)) > 8 and

                 to_number(substr(a.signtime, 1, 2)) <= 12 then

             '8-12点'

            when to_number(substr(a.signtime, 1, 2)) > 12 and

                 to_number(substr(a.signtime, 1, 2)) <= 16 then

             '12-16点'

            when to_number(substr(a.signtime, 1, 2)) > 16 and

                 to_number(substr(a.signtime, 1, 2)) <= 20 then

             '16-20点'

            when to_number(substr(a.signtime, 1, 2)) > 20 and

                 to_number(substr(a.signtime, 1, 2)) <= 24 then

             '20-24点'

          end)

          order by to_number(substr(a,1,instr(a,'-')-1))


最佳回答
0
黄源Lv6中级互助
发布于2019-11-1 10:25(编辑于 2019-11-1 11:01)

order by

substr((case

            when to_number(substr(a.signtime, 1, 2)) > 0 and

                 to_number(substr(a.signtime, 1, 2)) <= 4 then

             '0-4点'

            when to_number(substr(a.signtime, 1, 2)) > 4 and

                 to_number(substr(a.signtime, 1, 2)) <= 8 then

             '4-8点'

            when to_number(substr(a.signtime, 1, 2)) > 8 and

                 to_number(substr(a.signtime, 1, 2)) <= 12 then

             '8-12点'

            when to_number(substr(a.signtime, 1, 2)) > 12 and

                 to_number(substr(a.signtime, 1, 2)) <= 16 then

             '12-16点'

            when to_number(substr(a.signtime, 1, 2)) > 16 and

                 to_number(substr(a.signtime, 1, 2)) <= 20 then

             '16-20点'

            when to_number(substr(a.signtime, 1, 2)) > 20 and

                 to_number(substr(a.signtime, 1, 2)) <= 24 then

             '20-24点'

          end),0,instr(

(case

            when to_number(substr(a.signtime, 1, 2)) > 0 and

                 to_number(substr(a.signtime, 1, 2)) <= 4 then

             '0-4点'

            when to_number(substr(a.signtime, 1, 2)) > 4 and

                 to_number(substr(a.signtime, 1, 2)) <= 8 then

             '4-8点'

            when to_number(substr(a.signtime, 1, 2)) > 8 and

                 to_number(substr(a.signtime, 1, 2)) <= 12 then

             '8-12点'

            when to_number(substr(a.signtime, 1, 2)) > 12 and

                 to_number(substr(a.signtime, 1, 2)) <= 16 then

             '12-16点'

            when to_number(substr(a.signtime, 1, 2)) > 16 and

                 to_number(substr(a.signtime, 1, 2)) <= 20 then

             '16-20点'

            when to_number(substr(a.signtime, 1, 2)) > 20 and

                 to_number(substr(a.signtime, 1, 2)) <= 24 then

             '20-24点'

          end)

,'-'))


  • free_zz free_zz(提问者) 这个最好是一个时间区域,,有别的办法么
    2019-11-01 10:33 
  • 黄源 黄源 回复 free_zz(提问者) 看修改
    2019-11-01 11:00 
  • free_zz free_zz(提问者) 回复 黄源 这个我试过了 不行
    2019-11-01 11:16 
  • 黄源 黄源 回复 free_zz(提问者) order by to_number(substr(signtime,0,instr(\'-\',signtime)))
    2019-11-01 11:38 
最佳回答
0
qhlLv6中级互助
发布于2019-11-1 10:25


 order by (case


            when to_number(substr(a.signtime, 1, 2)) > 0 and


                 to_number(substr(a.signtime, 1, 2)) <= 4 then


             1


            when to_number(substr(a.signtime, 1, 2)) > 4 and


                 to_number(substr(a.signtime, 1, 2)) <= 8 then


             2


            when to_number(substr(a.signtime, 1, 2)) > 8 and


                 to_number(substr(a.signtime, 1, 2)) <= 12 then


             3


            when to_number(substr(a.signtime, 1, 2)) > 12 and


                 to_number(substr(a.signtime, 1, 2)) <= 16 then


            4


            when to_number(substr(a.signtime, 1, 2)) > 16 and


                 to_number(substr(a.signtime, 1, 2)) <= 20 then


             5


            when to_number(substr(a.signtime, 1, 2)) > 20 and


                 to_number(substr(a.signtime, 1, 2)) <= 24 then


             6


          end)


  • free_zz free_zz(提问者) 这个最好是一个时间区域,,有别的办法么
    2019-11-01 10:33 
  • qhl qhl 回复 free_zz(提问者) order by后面的case when用数字,前面查询用正常时间区域就好了,order by仅仅是排序的,不影响查询的
    2019-11-01 10:38 
  • free_zz free_zz(提问者) 回复 qhl 报错哦 ,不行。。完善了 麻烦看下
    2019-11-01 10:49 
  • qhl qhl 回复 free_zz(提问者) 看错误是group by有问题,你单独查下case when 那部分,看看是否还有除了这些之外的值(由于你这case when 没加else)
    2019-11-01 10:55 
  • axing axing 回复 free_zz(提问者) 这是什么数据库
    2019-11-01 11:01 
  • 4关注人数
  • 494浏览人数
  • 最后回答于:2019-11-6 17:32
    请选择关闭问题的原因
    确定 取消
    返回顶部