比如
A表:
a b c
---------------
e1 f1 g1
e1 f2 g2
e2 f1 g1
e3 f2 g2
B表:
a b
---------
f1 g1
f2 g2
则A÷B的结果应为 e1
这怎么用SQL语句表达??
...全文
24112打赏收藏
怎么用SQL语句表达 A÷B ?
假设有两表 A(a,b,c) 和 B(a,b) 要求A÷B 比如 A表: a b c --------------- e1 f1 g1 e1 f2 g2 e2 f1 g1 e3 f2 g2 B表: a b --------- f1 g1 f2 g2 则A÷B的结果应为 e1 这怎么用SQL语句表达??
--建立測試環境
create table d(a varchar(50),b varchar(50),c varchar(50))
insert into d
select 'e1', 'f1', 'g1' union all
select 'e1' , 'f2' , 'g2' union all
select 'e2', 'f1' , 'g1' union all
select 'e3', 'f2', 'g2'
create table d1(a varchar(50),b varchar(50))
insert into d1
select 'f1' , 'g1' union all
select 'f2' , 'g2'
--測試
select identity(int,1,1) ID ,d.a into #t from d , d1 where d.b=d1.a and d.c=d1.b
select A.a from #t A,#t B where a.a=b.a and a.id>b.id
--刪除測試用例
drop table d
drop table d1
drop table #t