解决方案 »

  1.   


    --不甚清楚楼主想怎么查,BETWEEN 不可以吗?
    SELECT * FROM TABLE WHERE MONEY BETWEEN 100 AND 200;
      

  2.   

    其实不是很清楚你要什么样的结果,按照自己的想法写了一下:
    TEST DATA:如果你的数据库支持wm_concat函数的话就好做很多:
    select t1.data_rank, wm_concat(t1.id) id
      from (select id,
                   t.money,
                   case
                     when t.money >= 100 and t.money < 200 then
                      '100—200的数据'
                     when t.money >= 200 and t.money < 400 then
                      '200—400的数据'
                     when t.money >= 400 and t.money < 1000 then
                      '400—1000的数据'
                     else
                      '其他数据'
                   end data_rank
              from test t) t1
     group by t1.data_rank;
    如果数据库版本较低不支持:
    select t2.data_rank, LTRIM(MAX(SYS_CONNECT_BY_PATH(T2.id, ',')), ',')
      from (select t1.id,
                   t1.data_rank,
                   row_number() over(partition by t1.data_rank order by t1.id) rn
              from (select id,
                           t.money,
                           case
                             when t.money >= 100 and t.money < 200 then
                              '100—200的数据'
                             when t.money >= 200 and t.money < 400 then
                              '200—400的数据'
                             when t.money >= 400 and t.money < 1000 then
                              '400—1000的数据'
                             else
                              '其他数据'
                           end data_rank
                      from test t) t1) t2
     START WITH T2.RN = 1
    CONNECT BY PRIOR RN = RN - 1
           AND PRIOR T2.data_rank = t2.data_rank
     GROUP BY T2.data_rank
     order by data_rank
    result as below:
      

  3.   

    Sorry,#3的TEST DATA 和RESULT的图弄反了
      

  4.   

    Sorry,#3的TEST DATA 和RESULT的图弄反了表示感谢!
      

  5.   

    Sorry,#3的TEST DATA 和RESULT的图弄反了表示感谢!

    中文字符乱码,你数据库字符集有问题,网上找到的答案是:
    alter database character set internal_use ZHS16GBK;
    不过好像有限制,你可以试试,实在不行就显示英文吧