日期:2014-05-17 浏览次数:20579 次
表ABC表ABC表AEF是一对多的关系
A B C
a1 b1 c1
a2 b2 c2
a3 b3 c3
表AEF
A E F
a1 e1 f1
a1 e1 f1
a2 e2 f2
a3 e3 f3
a3 e1 f3
a4 e1 f4
create table 表ABC(A varchar(10), B varchar(10),C varchar(10))
insert into 表ABC
select 'a1', 'b1', 'c1' union all
select 'a2', 'b2', 'c2' union all
select 'a3', 'b3', 'c3'
create table 表AEF(A varchar(10), E varchar(10), F varchar(10))
insert into 表AEF
select 'a1', 'e1', 'f1' union all
select 'a1', 'e1', 'f1' union all
select 'a2', 'e2', 'f2' union all
select 'a3', 'e3', 'f3' union all
select 'a3', 'e1', 'f3' union all
select 'a4', 'e1', 'f4'
select A
from 表AEF
group by A
having COUNT(case when E = 'e1' then 1 else null end) = COUNT(*)
/*
A
a1
a4
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-12-11 08:10:16
-- Version:
-