正 文

应用实例:Oracle的数据统计


www.7dspace.com  更新日期:2006-2-24 5:26:23  七度空间


  问:现在也有个数据统计的问题困绕着我。见如下数据,我要得到的是encode在哪几天里没有销售,求SQL语句,要考虑性能问题(表里有几百万条记录,而且每天都在增长)。

  有如下的数据

sdate     encode   count
--------  -------- ------
2006-1-1  1001     5
2006-1-1  1002     11
2006-1-2  1002     7
2006-1-2  1003     1
2006-1-3  1003     5
2006-1-3  1003     21
2006-1-4  1001     18
2006-1-4  1002     10

  现在想要得到如下形式的数据

sdate     encode
--------  -------
2006-1-2  1001
2006-1-3  1001
2006-1-3  1002

create table t(sdate varchar2(10),encode numeric,count numeric)
insert into t values('2006-1-1',1001,5 )
insert into t values('2006-1-1',1002,11)
insert into t values('2006-1-2',1002,7 )
insert into t values('2006-1-2',1003,1 )
insert into t values('2006-1-3',1003,5 )
insert into t values('2006-1-3',1003,21)
insert into t values('2006-1-4',1001,18)
insert into t values('2006-1-4',1002,10)

select
    a.sdate,b.encode
from
    (select distinct sdate  from t) a,
    (select distinct encode from t) b
where
    not exists(select * from t where sdate=a.sdate and encode=b.encode)
order by
    b.encode,a.sdate


上一篇:案例学习Oracle:细节很重要
下一篇:如何减少Jboss控制台和日志的信息输出
应用实例:Oracle的数据统计 作者: 来源:Techtarget
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐