表为
name date
a 2006/02/03
b 2006/02/04
c 2006/02/05
d 2006/02/07
e 2006/02/04要统计成
日 次数
2006/02/01 0
2006/02/02 0
2006/02/03 1
2006/02/04 2
2006/02/05 1
2006/02/06 0
2006/02/07 1
......
2006/02/30 0用select date, count(*) as flux from 表统计出来的只有表中有这一天的数据,没有的怎么办呢?
name date
a 2006/02/03
b 2006/02/04
c 2006/02/05
d 2006/02/07
e 2006/02/04要统计成
日 次数
2006/02/01 0
2006/02/02 0
2006/02/03 1
2006/02/04 2
2006/02/05 1
2006/02/06 0
2006/02/07 1
......
2006/02/30 0用select date, count(*) as flux from 表统计出来的只有表中有这一天的数据,没有的怎么办呢?
解决方案 »
- c# odp oracleblob效率太低
- 高分求助!oracle导入dmp问题
- oracle9i 包编译卡注,在10g下没有问题
- 请教一种设计,一种模式!
- 用exp条件导出多个表
- 连接oracle 10是,出错:无法解析指定的连接标识符
- 如何备份数据库中的表结构
- 请问一下,Oracle9i 第一次登录到Oracle Management Server的初始密码和用户名是什么
- 请推荐几本好的入门书,Oracle8i版本,可以从网上下载的。谢谢。
- 怎么让数据库自动更新
- 请问sqlca.sqlcode =-1007是什么错误?急!!!在线等
- ORA-01467: sort key too long的的问题?在线等...........
create table mydate(
rq varchar2(10)
);SQL> begin
2 for i in 1..10000 loop
3 insert into mydate values to_char(sysdate+i,'yyyy/mm/dd');
4 end loop;
5 end;
6 /最后,用子查询
select rq,
(select count(*) from yourtable where yourtable.rq=mydate.rq) flux
from mydate where rq<='2006/06/01';
create table mydate(
rq varchar2(10));begin
for i in 0..10000 loop
insert into mydate values (to_char((sysdate+i),'yyyy/mm/dd'));
end loop;
end;
/select rq,
(select count(*) from yourtable where yourtable.rq=mydate.rq) flux
from mydate where rq<='2006/06/01';
2 ( name varchar2(10), datefield date);Table createdSQL> select * from datetest;NAME DATEFIELD
---------- -----------SQL> insert into datetest(name,datefield) values('a',to_date('2006-02-03','yyyy-mm-dd'));1 row insertedSQL> insert into datetest(name,datefield) values('b',to_date('2006-02-04','yyyy-mm-dd'));1 row insertedSQL> insert into datetest(name,datefield) values('c',to_date('2006-02-05','yyyy-mm-dd'));1 row insertedSQL> insert into datetest(name,datefield) values('d',to_date('2006-02-07','yyyy-mm-dd'));1 row insertedSQL> insert into datetest(name,datefield) values('e',to_date('2006-02-04','yyyy-mm-dd'));1 row insertedSQL> select * from datetest;NAME DATEFIELD
---------- -----------
a 2006-2-3
b 2006-2-4
c 2006-2-5
d 2006-2-7
e 2006-2-4SQL>
SQL> select a.datefield,count(datetest.datefield)
2 from
3 (
4 select to_date('2006-02-01','yyyy-mm-dd') + rownum - 1 as datefield
5 from user_tab_cols
6 where rownum <= 28
7 ) A left join datetest on a.datefield = datetest.datefield
8 group by A.datefield
9 order by A.datefield;DATEFIELD COUNT(DATETEST.DATEFIELD)
----------- -------------------------
2006-2-1 0
2006-2-2 0
2006-2-3 1
2006-2-4 2
2006-2-5 1
2006-2-6 0
2006-2-7 1
2006-2-8 0
2006-2-9 0
2006-2-10 0
2006-2-11 0
2006-2-12 0
2006-2-13 0
2006-2-14 0
2006-2-15 0
2006-2-16 0
2006-2-17 0
2006-2-18 0
2006-2-19 0
2006-2-20 0DATEFIELD COUNT(DATETEST.DATEFIELD)
----------- -------------------------
2006-2-21 0
2006-2-22 0
2006-2-23 0
2006-2-24 0
2006-2-25 0
2006-2-26 0
2006-2-27 0
2006-2-28 028 rows selectedSQL>
2 from
3 (
4 select to_date('2006-02-01','yyyy-mm-dd') + rownum - 1 as datefield
5 from user_tab_cols
6 where rownum <= 31
7 ) A left join datetest on a.datefield = datetest.datefield
8 where to_char(A.datefield,'yyyymm') = '200602'
9 group by A.datefield
10 order by A.datefield;DATEFIELD COUNT(DATETEST.DATEFIELD)
----------- -------------------------
2006-2-1 0
2006-2-2 0
2006-2-3 1
2006-2-4 2
2006-2-5 1
2006-2-6 0
2006-2-7 1
2006-2-8 0
2006-2-9 0
2006-2-10 0
2006-2-11 0
2006-2-12 0
2006-2-13 0
2006-2-14 0
2006-2-15 0
2006-2-16 0
2006-2-17 0
2006-2-18 0
2006-2-19 0
2006-2-20 0DATEFIELD COUNT(DATETEST.DATEFIELD)
----------- -------------------------
2006-2-21 0
2006-2-22 0
2006-2-23 0
2006-2-24 0
2006-2-25 0
2006-2-26 0
2006-2-27 0
2006-2-28 028 rows selectedSQL>
select b.月日,a.次数 from
(select date ,coint(*) as 次数
from 表
group by 月份字字段) a,
(select 月日 as 次数
from dual
) b
where b.月日=a.date(*)
where b.月日=a.date(*)
==〉
where b.月日=a.date(+)
select trunc(sysdate,'mm')+rownum-1 all_day from all_objects
where rownum<=to_char(last_day(sysdate),'dd')
SQL> create table test_1 (a date,b number);Table createdExecuted in 0.19 secondsSQL> insert into test_1 values (sysdate,1);1 row insertedExecuted in 0.01 secondsSQL> insert into test_1 values (sysdate+20,3);1 row insertedExecuted in 0.01 seconds
SQL> insert into test_1 values (trunc(sysdate),2);1 row insertedExecuted in 0.02 secondsSQL> commit;Commit completeExecuted in 0.02 secondsSQL> select * from test_1;A B
----------- ----------
2006-5-8 1
2006-5-28 3
2006-5-8 2Executed in 0.141 secondsSQL>
SQL> Select b.date1,count(a.b) From test_1 a,
2 (Select trunc(last_day(add_months(Sysdate,-1)))+Rownum As date1 From user_objects Where Rownum<=
3 (Select last_day(Sysdate)-last_day(add_months(Sysdate,-1)) From dual)) b
4 Where b.date1=a.a(+)
5 Group By b.date1
6 /DATE1 COUNT(A.B)
----------- ----------
2006-5-1 0
2006-5-2 0
2006-5-3 0
2006-5-4 0
2006-5-5 0
2006-5-6 0
2006-5-7 0
2006-5-8 2
2006-5-9 0
2006-5-10 0
2006-5-11 0
2006-5-12 0
2006-5-13 0
2006-5-14 0
2006-5-15 0
2006-5-16 0
2006-5-17 0
2006-5-18 0
2006-5-19 0
2006-5-20 0DATE1 COUNT(A.B)
----------- ----------
2006-5-21 0
2006-5-22 0
2006-5-23 0
2006-5-24 0
2006-5-25 0
2006-5-26 0
2006-5-27 0
2006-5-28 1
2006-5-29 0
2006-5-30 0
2006-5-31 031 rows selectedExecuted in 0.931 seconds