分组后结果:
年份   年销售量    
2007   2000
2008   3000
2009  5000
2010   3210我想得到这样的结果:再显示一列
年份   年销售量       历年销售总量
2007   2000             2000
2008   3000             5000
2009  5000              10000
2010   3210             13210
...     ...               ....
用oracle语句怎么查询??
在线等待。

解决方案 »

  1.   

      select y,s, sum(s) over(order by s) from test3
      

  2.   

    select a.year,a.sale,( select sum(b.sale)
                           from a as b
                           where a.year >= b.year )
    from a
      

  3.   

    with temp as(
    select '2007' yyyy,2000 quantity from dual
    union all
    select '2008' yyyy,3000 quantity from dual
    union all
    select '2009' yyyy,5000 quantity from dual
    union all
    select '2010' yyyy,3210 quantity from dual
    )
    select yyyy,sum(quantity) over(order by quantity) from temp order by yyyy
      

  4.   

    看错了,少了一项
    with temp as(
    select '2007' yyyy,2000 quantity from dual
    union all
    select '2008' yyyy,3000 quantity from dual
    union all
    select '2009' yyyy,5000 quantity from dual
    union all
    select '2010' yyyy,3210 quantity from dual
    )
    select yyyy,quantity,sum(quantity) over(order by quantity) from temp 
      

  5.   

    怎么这样的问题还是在问啊???
    在问的时候自己先想哈,或者不懂网上查一下,类似的问题已经发过无数遍了,哎!!~~楼主,还是再给你贴过来吧,三种实现方法,所以你可以看看。以后别三思而后行.问题: 
    销售表sale中有如下数据,记录了每个月的销售额情况 
    SQL> select * from sale; MONTH          SELL 
    ------ ------------ 
    200001      1000.00 
    200002      2000.00 
    200003      4000.00 
    200004    66454.00 
    200005      2344.00 
    200101    81233.00 
    200103    441241.00 
    200210    345441.00 
    200305    43113.00 9 rows selected 现要得到如下显示数据: 
    MONTH        SUM 
    ------ ---------- 
    200001      1000 
    200002      3000 
    200003      7000 
    200004      73454 
    200005      75798 
    200101    157031 
    200103    598272 
    200210    943713 
    200305    986826 即:累加每月销售额。 
    ====================================== 
    我初步用了三种方法实现该需求。 第一种:自连接 
    SQL> select b.month,sum(a.sell) from sale a,sale b 
      2  where a.month <=b.month 
      3  group by b.month 
      4  order by b.month; 第二种:子查询 
    SQL> select a.month, 
      2  (select sum(b.sell) from sale b where b.month <=a.month) 
      3  from sale a; 第三种:利用Oracle8.1.6开始提供的分析函数实现(超简单!)。 
    SQL> select month,sum(sell)over(order by month) from sale; 
    或者 
    SQL> select month,sum(sell)over(order by month rows between unbounded preceding and current row ) from sale; 
    或者 
    SQL> select month,sum(sell)over(order by month range unbounded preceding ) from sale; 
    因为这三个语句是等效的。
      

  6.   

    SQL> with tt as
      2  (select 2007 年份,  2000 年销售量 from dual
      3  union all select 2008 , 3000 from dual
      4  union all select 2009 , 5000 from dual
      5  union all select 2010 , 3210 from dual
      6  )select tt.*, sum(年销售量) over(order by 年份) 历年销售总量  from tt;
     
            年份       年销售量       历年销售总量
    ---------- ---------- ------------
          2007       2000         2000
          2008       3000         5000
          2009       5000        10000
          2010       3210        13210
      

  7.   

    不错
    1楼和3楼的order by后的列名写错了