oraclesql - 搜索缺少的salesimport数据

时间:2016-06-17 07:10:20

标签: sql oracle

我有两张桌子(一张有关于' salesimports'以及下一张有关商店的数据的数据)。

这是一个示例数据:

shop    city    importid    importtype  importtime  committime  endtime
S410    KURSK   1107597374  PSCN    2016-06-17  2016-06-17  2016-06-17
S004    KIEV    1107595750  PSCN    2016-06-17  2016-06-17  2016-06-17
S230    WARSAW  1107595594  PSCN    2016-06-17  2016-06-17  2016-06-17
S115    LVIV    1107595507  PSCN    2016-06-17  2016-06-17  2016-06-17
S220    PRAGUE  1107595458  PSCN    2016-06-17  2016-06-17  2016-06-17
S179    MINSK   1107595328  PSCN    2016-06-17  2016-06-17  2016-06-17
S247    HOMEL   1107595264  PSCN    2016-06-17  2016-06-17  2016-06-17
S202    ROSTOV  1107595114  PSCN    2016-06-17  2016-06-17  2016-06-17
S132    BERLIN  1107595112  PSCN    2016-06-17  2016-06-17  2016-06-17

我用来从两个表中获取数据的选择:

select f.shid shop, f.ctid city, i.limportref importid, i.simporttype importtype, 
       centrala_user.borlanddatetostr(i.itp) importtime, 
       centrala_user.borlanddatetostr(i.gtp) committtime, 
       centrala_user.borlanddatetostr(i.edp) endtime
from oracla.imports i 
join oracla.firm f on i.shid = f.shid
where f.byact = 0 
and f.bytype = 0
and i.simporttype not in ('PSXN')
order by i.itp desc;

我的计划是获得一个选择权,它会向我提供有关在过去几天内没有进口商品的信息,或者整个' salesdata'在salesimports表中缺少一家商店。

我尝试了很少的解决方案'而不是'和'并且不存在'但它并没有给我一个我想要的结果。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你没有表现出来,你尝试了什么。你尝试过这样的事情吗?

select f.*, 
      (select max(centrala_user.borlanddatetostr(i.itp)) from oracla.imports i where i.simporttype not in ('PSXN') and i.shid=f.shid) as last_import_date
  from oracla.firm f 
 where f.byact = 0 
   and f.bytype = 0
   and f.shid not in  (
      select distinct i.shid
        from oracla.imports i
       where i.simporttype not in ('PSXN')
         and centrala_user.borlanddatetostr(i.itp) > trunc(add_months(sysdate,-1))
   )   

因为不清楚,最后一天是什么意思,我用了一个星期(trunc(sysdate -7))