其实非常简单,却让人头疼!
资料:
table:
month total
3 50
5 60
6 80
用sql实现
month total
1 0
2 0
3 50
4 0
..............
..............
我的开发环境受限制,不能新建表和用存储过程!
sql好难写啊!有没有好办法!有兴趣话请看下面的问题!
以上我把问题简单化其实:
table:
date1 number
2001-6-12 36
2001-12-23 23
2002-2-3 60
2002-2-25 20
2002-4-6 45
2002-4-27 30查询 2002.1 到2002.5
实现:
month totol increase/decrease
(去年12)12 23 0
1 0 -23
2 80 +57
3 0 -80
4 75 +75
5 0 -75高手们留下您的墨宝吧!
资料:
table:
month total
3 50
5 60
6 80
用sql实现
month total
1 0
2 0
3 50
4 0
..............
..............
我的开发环境受限制,不能新建表和用存储过程!
sql好难写啊!有没有好办法!有兴趣话请看下面的问题!
以上我把问题简单化其实:
table:
date1 number
2001-6-12 36
2001-12-23 23
2002-2-3 60
2002-2-25 20
2002-4-6 45
2002-4-27 30查询 2002.1 到2002.5
实现:
month totol increase/decrease
(去年12)12 23 0
1 0 -23
2 80 +57
3 0 -80
4 75 +75
5 0 -75高手们留下您的墨宝吧!
解决方案 »
- 关于oracle查询问题................高人啊~~~~~~~
- vc 通过oci 访问Nmber数据类型值总是0
- 语句优化 实在是太慢了
- 還是外鍵的問題,幫幫我,謝了
- 求购OCA: Oracle 10g 管理 I 学习指南(1Z0-042)
- 在线等 OracleOraHome90TNSListener自动终止
- [que]数据增量备份和恢复
- 这个存储过程有何错误?
- 存储过程中的输出参数可以定义长度的吗?
- zhaoyongzhu进来领分
- 关于QUEST的工具TODA,大家有使用过吗?
- 论者有分 ,欢迎大家讨论, Oracle8i 与 Oracle9i 之间数据的通信 ,移植 , 导入导出等等还有其他兼容性问题 ?
where all_source.rownum=tb.rownum(+) and rownum<(select max(month) from tb);
(select rownum rn from dba_objects where rownum<=12)a,table b,
where a.rn=b.month(+)
(select to_char(date1,'yyyymm') date1,sum(number) totol from table where date1 between to_date('2002-01','yyyy-mm') and to_Date('2002-05','yyyy-mm') group by to_char(date1,'yyyymm'))
查询 2002.1 到2002.5 这个只是我举个例子,其实是差数,从网页上传来的!
而且2001.12 月也是我大个比喻,在实际情况,数据库中可能没有2001.12记录!
但是查询2002.1 到2002.5 时 要把去年的2001.12 输出!
而且当中月没有记录也要显示。
month totol increase/decrease
(去年12)12 0 0
1 0 0
2 80 +80
3 0 -80
4 75 +75
5 0 -75