`

不存在的数据

SQL 
阅读更多

表A 
id name time 
1 aa 2009-01-01 
 
2 aa 2009-01-02 
 
8 aa 2009-01-03 
 
10 aa 2009-01-04 
 
15 aa 2009-01-08 


id不连续,time格式固定每天接收一次,不会重复只会缺少,我要如何得到下面这些数据? 
2009-01-05 
 
2009-01-06 
 
2009-01-07 

因为数据量比较大(大概有1000+w数据),不想都遍历出来用程序解决。 

javaeye回答问题的人真少。。。CSDN贴出来一会就解决了。。。 

Sql代码 
create table test (user_id number, user_name varchar2(20), opt_time date);    
begin    
insert into test values(1, 'aa', to_date('2009-01-01 00:10', 'yyyy-mm-dd hh24:mi'));    
insert into test values(2 , 'aa', to_date('2009-01-01 00:20', 'yyyy-mm-dd hh24:mi'));    
insert into test values(5 , 'aa', to_date('2009-01-01 00:30', 'yyyy-mm-dd hh24:mi'));    
insert into test values(10, 'aa', to_date('2009-01-01 00:50', 'yyyy-mm-dd hh24:mi'));    
insert into test values(11, 'aa', to_date('2009-01-01 01:20', 'yyyy-mm-dd hh24:mi'));    
insert into test values(12, 'aa', to_date('2009-01-01 01:30 ', 'yyyy-mm-dd hh24:mi'));    
commit;    
end;    
  
  
select opt_time    
  from (select to_date('2009-01-01', 'yyyy-mm-dd') + level * 10 / 60 / 24 opt_time    
          from dual    
        connect by level <= 12 * 6    
        union    
        select to_date('2009-01-01 12:00', 'yyyy-mm-dd hh24:mi') +    
              level * 10 / 60 / 24 opt_time    
          from dual    
        connect by level < 12 * 6)    
where opt_time not in (select opt_time from test);   

    

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics