2013-02-12 62 views
0

首先,让我从我使用的表开始。他们看起来像这样:选择任何数据表中不存在字符串的ID

Table - Transaction 
=================== 
trans_id 
name 

Table - Checkpoint 
================== 
trans_id 
checkpoint_id 
checkpoint_data 

事务可以有多个检查点,并且检查点只能有一个事务。

我无法形成一条SQL语句,它将选择某个名称的所有事务的trans_id,该名称在任何相关检查点中不包含checkpoint_data中的某些字符串。

此SQL语句的外观如何?我使用的是Oracle,但是任何SQL应指向我朝着正确的方向

回答

1
select trans_id 
from transactions t 
left outer join checkpoint c on c.trans_id = t.trans_id 
where t.name = 'transaction name' 
group by t.trans_id 
having sum(case when contains(checkpoint_data, 'some string') > 0 
       then 1 
       else 0 
      end) = 0 
+0

+1。 。 。你可以添加问题中提到的'where name = SOMENAME'条件。 – 2013-02-12 18:51:11

+0

@GordonLinoff:谢谢。完全忘了那个。 – 2013-02-12 18:52:21

0
Select distinct(ch.trans_id) from checkpoint ch join transaction t on ch.trans_id=t.trans_id and t.name like '%test%' and ch.chech_point not like '%exclude%' 
相关问题