本帖最后由 lisen1987 于 2012-05-02 15:19:35 编辑

解决方案 »

  1.   

    下面是查询当前是当年的第几个季度的语句,希望有帮助
    select to_char(sysdate ,'yyyy/q') as quarter-- oracle求当年的第几季度
    from dual
      

  2.   

    我一般按如下形式写:
    select yearno,qno,sum(amount) from (
    select to_char(日期字段,'yyyy') as yearNo, to_char(日期字段,'1') as qNo,汇总字段 as amount from 表名
    where 过滤条件
    )
    group by rollup(yearno,qno)
      

  3.   


    with test as(
    select 50 amt, to_date('09-03-2011','dd-mm-yyyy') dat from dual
    union all
    select 40 amt, to_date('06-03-2011','dd-mm-yyyy') dat from dual
    union all
    select 30 amt, to_date('09-05-2011','dd-mm-yyyy') dat from dual
    union all
    select 20 amt, to_date('09-04-2011','dd-mm-yyyy') dat from dual
    union all
    select 10 amt, to_date('09-07-2011','dd-mm-yyyy') dat from dual
    union all
    select 60 amt, to_date('09-08-2011','dd-mm-yyyy') dat from dual
    union all
    select 80 amt, to_date('09-11-2011','dd-mm-yyyy') dat from dual
    union all
    select 70 amt, to_date('09-12-2011','dd-mm-yyyy') dat from dual
    union all
    select 55 amt, to_date('09-02-2012','dd-mm-yyyy') dat from dual
    )
    select amt, to_char(dat,'q') quater,to_char(dat,'yyyy')  year
    from test没想出来,把测试数据贴出来,等结果中~
      

  4.   

    楼主的意思应该是这样,求当前5个季度的汇总,这个可以用pl/sql写出来,分别求出当前所在季度以及前四个季度的时间段,然后对应时间段用between求sum,盼高手用一句话写出来.
      

  5.   

    想起来了,晕with test as(
    select 50 amt, to_date('09-03-2011','dd-mm-yyyy') dat from dual
    union all
    select 40 amt, to_date('06-03-2011','dd-mm-yyyy') dat from dual
    union all
    select 30 amt, to_date('09-05-2011','dd-mm-yyyy') dat from dual
    union all
    select 20 amt, to_date('09-04-2011','dd-mm-yyyy') dat from dual
    union all
    select 10 amt, to_date('09-07-2011','dd-mm-yyyy') dat from dual
    union all
    select 60 amt, to_date('09-08-2011','dd-mm-yyyy') dat from dual
    union all
    select 80 amt, to_date('09-11-2011','dd-mm-yyyy') dat from dual
    union all
    select 70 amt, to_date('09-12-2011','dd-mm-yyyy') dat from dual
    union all
    select 55 amt, to_date('09-02-2012','dd-mm-yyyy') dat from dual
    )
    select quater, sum(amt)
    from (
    select amt, to_char(dat,'q') quater,to_char(dat,'yyyy')  year
    from test)
    group by rollup(year, quater)
    having quater is not null
    order by year1 90
    2 50
    3 70
    4 150
    1 55
      

  6.   

    Q 季度,1~3月为第一季度 Select to_char(sysdate,’Q’) from dual; 2表示第二季度①