我有以下查询,我需要列
的唯一值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数据库
答案 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
在事务表中,则应将条件移动到子查询。