你上面的语句条件:
select to_char(b.cre_date,'yyyymmdd'),count(*)
from tos_product_order b
where to_char(b.cre_date,'yyyymm') = '200309'
group by to_char(b.cre_date,'yyyymmdd')
中的where字句 是限制了订单的日期吗?去掉就应该满足你的统计要求了吧!
select to_char(b.cre_date,'yyyymmdd'),count(*)
from tos_product_order b
where to_char(b.cre_date,'yyyymm') = '200309'
group by to_char(b.cre_date,'yyyymmdd')
中的where字句 是限制了订单的日期吗?去掉就应该满足你的统计要求了吧!
解决方案 »
- conn / as sysdba与OracleDBConsoleorcl的冲突
- oracler biee 约束问题
- SQL查询语句
- ORA-00979 与 ORA-02063 错误原因?
- 怎么样找到Oracle的跟踪文件
- help me 有关oracle8.03还原的问题,总是还原不正确。请高手指点
- oracle8i中如何取得一表table的ddl语句
- 如何启用归档日志
- 请大家一定帮忙!谁能提供一个完整的从Ctree数据库迁移数据到oracle数据库的方案,给建议也给分,特急!
- PLSQL Developer 登录时datadase选项下拉为空???
- 一个复杂的交叉报表的sql写法
- 请问oracle 中定位字符串位置的方法是什么呀, 如pos等 谢谢
select
NVL(select to_char(b.cre_date,'yyyymmdd'),count(*)
from tos_product_order b
where to_char(b.cre_date,'yyyymm') = '200309'
group by to_char(b.cre_date,'yyyymmdd'),
0)
from dual;
from (
select to_char(b.cre_date,'yyyymmdd') dt,count(*) c
from tos_product_order b
where to_char(b.cre_date,'yyyymm') = '200309'
group by to_char(b.cre_date,'yyyymmdd')
) t,(select to_date('200309','yyyymm')+rownum-1 rdt,0 c1
from user_objects
where rownum<=to_char(last_day(to_date('200309','yyyymm')),'dd')
) tt
where tt.edt=tt.dt(+)
好办法:).
你未测试:)
好像有点问题
-------------------
2003-09-01 00:00:00
2003-09-02 00:00:00
2003-09-02 00:00:00
2003-09-03 00:00:00
2003-09-06 00:00:00
2003-09-06 00:00:00已选择6行。已用时间: 00: 00: 00.94
13:37:06 SQL> select rdt,nvl(c,0)
13:37:44 2 from (
13:37:50 3 select to_char(b.cre_date,'yyyymmdd') dt,count(*) c
13:37:50 4 from tbdemo b
13:37:50 5 where to_char(b.cre_date,'yyyymm') = '200309'
13:37:50 6 group by to_char(b.cre_date,'yyyymmdd')
13:37:50 7 ) t,(select to_date('200309','yyyymm')+rownum-1 rdt,0 c1
13:37:50 8 from all_source
13:37:50 9 where rownum<=to_char(last_day(to_date('200309','yyyymm')),'dd')
13:37:51 10 ) tt
13:37:51 11 where tt.rdt=t.dt(+);RDT NVL(C,0)
------------------- ----------
2003-09-01 00:00:00 1
2003-09-02 00:00:00 2
2003-09-03 00:00:00 1
2003-09-04 00:00:00 0
2003-09-05 00:00:00 0
2003-09-06 00:00:00 2
2003-09-07 00:00:00 0
2003-09-08 00:00:00 0
2003-09-09 00:00:00 0
2003-09-10 00:00:00 0
2003-09-11 00:00:00 0RDT NVL(C,0)
------------------- ----------
2003-09-12 00:00:00 0
2003-09-13 00:00:00 0
2003-09-14 00:00:00 0
2003-09-15 00:00:00 0
2003-09-16 00:00:00 0
2003-09-17 00:00:00 0
2003-09-18 00:00:00 0
2003-09-19 00:00:00 0
2003-09-20 00:00:00 0
2003-09-21 00:00:00 0
2003-09-22 00:00:00 0RDT NVL(C,0)
------------------- ----------
2003-09-23 00:00:00 0
2003-09-24 00:00:00 0
2003-09-25 00:00:00 0
2003-09-26 00:00:00 0
2003-09-27 00:00:00 0
2003-09-28 00:00:00 0
2003-09-29 00:00:00 0
2003-09-30 00:00:00 0已选择30行。已用时间: 00: 00: 04.63
13:37:56 SQL>
做一个函数实现
问题是,当某一天有数据出现的时候.这个SQL就有问题了.
SQL> select rdt,nvl(c,0)
2 from (
3 select to_char(b.rbrq,'yyyymmdd') dt,count(*) c
4 from p_zjrb b
5 where to_char(b.rbrq,'yyyymm') = '200307'
6 group by to_char(b.rbrq,'yyyymmdd')
7 ) t,(select to_date('200307','yyyymm')+rownum-1 rdt,0 c1
8 from all_source
9 where rownum<=to_char(last_day(to_date('200307','yyyymm')),'dd')
10 ) tt
11 where tt.rdt=t.dt(+)
12 ;select rdt,nvl(c,0)
from (
select to_char(b.rbrq,'yyyymmdd') dt,count(*) c
from p_zjrb b
where to_char(b.rbrq,'yyyymm') = '200307'
group by to_char(b.rbrq,'yyyymmdd')
) t,(select to_date('200307','yyyymm')+rownum-1 rdt,0 c1
from all_source
where rownum<=to_char(last_day(to_date('200307','yyyymm')),'dd')
) tt
where tt.rdt=t.dt(+)ORA-01861: 文字与格式字符串不匹配
from (
select to_char(b.rbrq,'yyyymmdd') dt,count(*) c
from p_zjrb b
where to_char(b.rbrq,'yyyymm') = '200307'
group by to_char(b.rbrq,'yyyymmdd')
) t,(select to_char(to_date('200307','yyyymm')+rownum-1,'yyyymmdd') rdt,0 c1
from all_source
where rownum<=to_char(last_day(to_date('200307','yyyymm')),'dd')
) tt
where tt.rdt=t.dt(+)
------------------------------------------------------------1884
1884SUBSTR(BASE_ID,1,INSTR(BASE_ID,'4'))
------------------------------------------------------------
選取了 18 列SQL> SELECT NVL(SUBSTR(BASE_ID,1,INSTR(BASE_ID,'4')),0) FROM BAO_TEMP
2 /NVL(SUBSTR(BASE_ID,1,INSTR(BASE_ID,'4')),0)
------------------------------------------------------------
0
1884
0
0
0
0
0
0
0
0
1884NVL(SUBSTR(BASE_ID,1,INSTR(BASE_ID,'4')),0)
------------------------------------------------------------
0
0
0
0
0
0
0選取了 18 列