表结构
SID SALE SDATE REMARK
----- ---------- ---------------- --------------
1 200 201003 无
2 4500 201002 无
3 2300 201001 无
4 2600 200912 无
5 1200 200911 无
6 3300 200910 无
7 3600 200909 无
8 1900 200908 无
9 1400 200907 无
10 300 200906 无
11 1200 200905 无
12 2200 200904 无
13 2400 200903 无
14 2600 200902 无
15 2300 200901 无
16 2800 200812 无
17 3200 200811 无想要的结果是:
用最近月份做条件 查询出来本月以及前12个月的销售额
201003 201002 201001 200912 200911 200910 200909 200908 200907 200906 200905 200904 200903
200 4500 2300 2600 1200 3300 3600 1900 1400 300 1200 2200 2400 就是根据那个日期条件 递减请大家帮帮忙~实在想不出来
先谢谢了
SID SALE SDATE REMARK
----- ---------- ---------------- --------------
1 200 201003 无
2 4500 201002 无
3 2300 201001 无
4 2600 200912 无
5 1200 200911 无
6 3300 200910 无
7 3600 200909 无
8 1900 200908 无
9 1400 200907 无
10 300 200906 无
11 1200 200905 无
12 2200 200904 无
13 2400 200903 无
14 2600 200902 无
15 2300 200901 无
16 2800 200812 无
17 3200 200811 无想要的结果是:
用最近月份做条件 查询出来本月以及前12个月的销售额
201003 201002 201001 200912 200911 200910 200909 200908 200907 200906 200905 200904 200903
200 4500 2300 2600 1200 3300 3600 1900 1400 300 1200 2200 2400 就是根据那个日期条件 递减请大家帮帮忙~实在想不出来
先谢谢了
解决方案 »
- Sql developer连接Oracle一直测试连接也没报错,就是连不上!
- Oracle 查询一个表中的最后一列数据
- 动态Sql中报错:缺失逗号
- 请教一个在delete语句中inner join的问题
- 为什么我设置varchar2(4000),插入700多个汉字时就说超过长度!
- 表分区创建后,如何修改分区的范围(范围分区)
- 狂晕,300分,为什么改变条件的顺序会影响查询结果???
- 初学Oracle,安装的是8i,那有以下的图书的电子版下载?好学习学习。开发人员....
- 为什么建表报‘ERROR 位于第 1 行:ORA-00922: 缺少或无效选项’
- 建表语句中没有分区信息,DBA_tab_partitions中却能查到分区信息
- 问个起别名的小问题。
- 高手 请读一下这段SQL
from tab
where sdate <=trunc(sysdate,'dd')
and sdate>=trunc(sysdate-12,'dd');
months_between是查两个日期之间的月数。
select 1 sid, 200 sale, '201003' sdate, '无' re from dual union all
select 2 sid, 4500 sale, '201002' sdate, '无' re from dual union all
select 3 sid, 2300 sale, '201001' sdate, '无' re from dual union all
select 4 sid, 2600 sale, '200912' sdate, '无' re from dual union all
select 5 sid, 1200 sale, '200911' sdate, '无' re from dual union all
select 6 sid, 3300 sale, '200910' sdate, '无' re from dual union all
select 7 sid, 3600 sale, '200909' sdate, '无' re from dual union all
select 8 sid, 1900 sale, '200908' sdate, '无' re from dual union all
select 9 sid, 1400 sale, '200907' sdate, '无' re from dual union all
select 10 sid, 300 sale, '200906' sdate, '无' re from dual union all
select 11 sid, 1200 sale, '200905' sdate, '无' re from dual union all
select 12 sid, 2200 sale, '200904' sdate, '无' re from dual union all
select 13 sid, 2400 sale, '200903' sdate, '无' re from dual union all
select 14 sid, 2600 sale, '200902' sdate, '无' re from dual union all
select 15 sid, 2300 sale, '200901' sdate, '无' re from dual union all
select 16 sid, 2800 sale, '200812' sdate, '无' re from dual union all
select 17 sid, 3200 sale, '200811' sdate, '无' re from dual)
select *
from tab
where sdate between to_char(add_months(sysdate, -12), 'yyyymm') and
to_char(sysdate, 'yyyymm')
order by sdate desc;
from tab
where sdate between to_char(add_months(sysdate, -12), 'yyyymm') and
to_char(sysdate, 'yyyymm')
order by sdate desc;