获取唯一列值以及其他值。使用内部联接时的列

时间:2018-03-19 20:25:52

标签: sql oracle11g oracle10g

我有以下查询,我需要列

的唯一值
Select unique(t.id), log.* 
from tableA log 
inner join tableT t on t.id1=log.id1 
where log.time>=(somedate) 
and log.time<(somedate) 
and ref-id=20 
and ref-id=30 
and t.id not in (select unique t.id 
                 from   tableA log 
                 inner join tableT t on t.id1=log.id1 
                 where log.time>=(somedate) 
                 and log.time<(somedate) 
                 and ref-id=20 
                 and ref-id=30);

我没有获得t.id的独特价值。任何人都可以帮忙吗?我正在使用oracle数据库

1 个答案:

答案 0 :(得分:0)

这样的事情怎么样?

Select t.id, log.* 
from tableA log inner join
     (select t.*, row_number() over (partition by id1 order by id) as seqnum
      from tableT t
     ) t
     on t.id1 = log.id1 
where log.time >= (somedate) and
      log.time < (somedate) and
      t.seqnum = 1
      ref_id = 20 and ref_id = 30 -- this is ALWAYS false, but I'm ignoring that

注意:

  • 我不知道子查询应该做什么。
  • ref_id上的条件将始终评估为FALSE,因此逻辑几乎肯定不是您想要的。
  • 如果ref_id在事务表中,则应将条件移动到子查询。