本帖最后由 mojo_mask 于 2011-12-02 14:40:52 编辑

解决方案 »

  1.   

    with t  as (
     select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from  dual union all                                            
     select 1 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from  dual union all
     select 1 id ,date '2011-12-3' ddate, '09:30' begin, '10:00' end from  dual union all
     select 2 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from  dual union all
     select 2 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from  dual union all
     select 2 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from  dual union all
     select 3 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from  dual union all
     select 3 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from  dual union all
     select 3 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from  dual 
     )
     select id ,wm_concat(a),wm_concat(b),wm_concat(c) from (
     select  id,decode(to_char(ddate,'dy'),'星期五',(begin||'-'||end)) a,
                decode(to_char(ddate,'dy'),'星期六',(begin||'-'||end)) b,
               decode(to_char(ddate,'dy'),'星期日',(begin||'-'||end)) c
               from t ) tt
               group by tt.id
    -----  1 09:30-10:00,10:30-11:00 09:30-10:00
    2 09:30-10:00,10:30-11:00         09:30-10:00
    3 09:30-10:00,10:30-11:00         09:30-10:00
      

  2.   


    with t  as (
     select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from  dual union all                                            
     select 1 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from  dual union all
     select 1 id ,date '2011-12-3' ddate, '09:30' begin, '10:00' end from  dual union all
     select 2 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from  dual union all
     select 2 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from  dual union all
     select 2 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from  dual union all
     select 3 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from  dual union all
     select 3 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from  dual union all
     select 3 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from  dual 
     )
    这些语句的目的是为了建立测试数据,你有实际的表,不用写前面这些。
    直接从实际表中的查询即可。