分组后结果:
年份 年销售量
2007 2000
2008 3000
2009 5000
2010 3210我想得到这样的结果:再显示一列
年份 年销售量 历年销售总量
2007 2000 2000
2008 3000 5000
2009 5000 10000
2010 3210 13210
... ... ....
用oracle语句怎么查询??
在线等待。
年份 年销售量
2007 2000
2008 3000
2009 5000
2010 3210我想得到这样的结果:再显示一列
年份 年销售量 历年销售总量
2007 2000 2000
2008 3000 5000
2009 5000 10000
2010 3210 13210
... ... ....
用oracle语句怎么查询??
在线等待。
解决方案 »
- 如何在Oracle中调用MSSQL的存储过程?
- PLSQL Developer登陆的问题(oracle) 大神求帮忙啊~
- oci,occi,ocilib哪个更好用
- -----Oracle 10g 急救--------
- 带排序的分页查询使用不同的查询计划差异很大,怎么解决呢?
- ORACLE 9i 一台机器安装Server 同时开两个数据库在C盘D盘 问题,能用高级复制功能实现C盘的数据库复制到D盘的数据库吗?
- 树表查询问题
- 请问如何把POWERDESINER建立的表结构倒入到ORACLE9数据库,谢谢,急急!!!!
- oracle的数据库表结构导出
- 请问ORACLE的预定义用户名和密码是manager和system吗
- 请教个写法
- 大家好,帮我看看这个关于decode的语句
from a as b
where a.year >= b.year )
from a
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
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
在问的时候自己先想哈,或者不懂网上查一下,类似的问题已经发过无数遍了,哎!!~~楼主,还是再给你贴过来吧,三种实现方法,所以你可以看看。以后别三思而后行.问题:
销售表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;
因为这三个语句是等效的。
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
1楼和3楼的order by后的列名写错了