解决方案 »

  1.   

    按你目前给出的,周六周日我不知道你准备如何处理,目前按照一周从周日到周六的方式给你写代码吧
    假设你的原始表日期字段为D
    with T AS (
    select to_char(D,'yyyy-mm') 月度,ceil((to_char(D,'dd')-to_char(D,'d')+to_char(trunc(D,'month'),'d'))/7) 周次,sum(金额) 金额
    FROM table1
    group by to_char(D,'yyyy-mm'),ceil((to_char(D,'dd')-to_char(D,'d')+to_char(trunc(D,'month'),'d'))/7)
    )
    select 月度,
    SUM(DECODE(周次,1,金额)) 第一周金额,
    SUM(DECODE(周次,2,金额)) 第二周金额,
    ……
    from T
    group by 月度