本帖最后由 Lyu_KingT 于 2011-01-20 11:16:08 编辑

解决方案 »

  1.   


      1  with t as (
      2  select trunc(hire_date,'mm') hire_month, count(employee_id) cnt
      3  from employees
      4  group by trunc(hire_date,'mm')
      5  )
      6  select to_char(hire_month,'yyyy-mm') hire_month,cnt this_year,
      7  nvl((select cnt from t where t1.hire_month-interval '12' month=hire_month),0) last_year
      8* from t t1 order by hire_month
    SQL> /HIRE_MO  THIS_YEAR  LAST_YEAR
    ------- ---------- ----------
    2001-01          1          0
    2002-06          4          0
    2002-08          2          0
    2002-12          1          0
    2003-05          2          0
    2003-06          1          4
    2003-07          1          0
    2003-09          1          0
    2003-10          1          0
    2004-01          2          0
    2004-02          2          0
    2004-03          1          0
    2004-05          1          2
    2004-06          1          1
    2004-07          1          1
    2004-08          1          0
    2004-10          1          1
    2005-01          3          2
    2005-02          2          2
    2005-03          6          1
    2005-04          1          0
    2005-06          2          1
    2005-07          2          1
    2005-08          4          1
    2005-09          3          0
    2005-10          3          1
    2005-11          1          0HIRE_MO  THIS_YEAR  LAST_YEAR
    ------- ---------- ----------
    2005-12          2          0
    2006-01          3          3
    2006-02          3          2
    2006-03          5          6
    2006-04          3          1
    2006-05          1          0
    2006-06          1          2
    2006-07          3          2
    2006-08          1          4
    2006-09          1          3
    2006-11          2          1
    2006-12          1          2
    2007-01          1          3
    2007-02          3          3
    2007-03          3          5
    2007-04          1          3
    2007-05          2          1
    2007-06          2          1
    2007-08          1          1
    2007-10          1          0
    2007-11          2          2
    2007-12          3          1
    2008-01          4          1
    2008-02          3          3
    2008-03          2          3
    2008-04          2          153 rows selected.
      

  2.   

    回复:xman_78tom谢谢测试成功了,请问,分析函数里面有相应的实现办法吗?