两个关系模式R = (A, B, C, D) 和 S = (B, C, D), 用他们创建了两个关系r(R) and s(S)

用SQL query写出r ÷ s的等值式(equivalent expression)
2024-12-05 05:27:22
推荐回答(1个)
回答1:

第一种方法:select A from r T1 where not exists(
select B,C,D from s where not exists(
select A from r T2 where T2.B=s.B and T2.C=s.C and T2.D=s.D and T1.A=T2.A))
第二种方法:
SELECT DISTINCT A
FROM r a
WHERE NOT EXISTS
(SELECT * FROM
(SELECT B,C,D FROM r b
WHERE a.A = b.A) x
RIGHT OUTER JOIN
(SELECT B,C,D FROM s) y
ON x.B = y.B and x.C=y.C and x.D=y.D

WHERE (x.B IS NULL and x.C is null and x.D is null))
你试一下行不行,不行的话,但基本上就是这个思路,可以自己改一改。