我想将具有 where not in 子句的 sql 查询转换为元组关系演算。Existential 和 Universal 量词仅实现 where exists 和 where not exists 子句,所以我想知道如何实现 where not in?
我的表是serves(bar,beer),frequents(drinker,bar),likes(drinker,beer)
。以下查询选择只经常光顾提供他们喜欢的啤酒的酒吧的饮酒者。
select distinct f2.drinker from frequents f2 where f2.drinker not in (select f1.drinker from frequents f1 where (f1.bar,f1.drinker) not in (select f.bar,f.drinker from frequents f,serves s,likes l where l.beer=s.beer and f.bar=s.bar and f.drinker=l.drinker))
如果有人可以解释我如何在 TRC 中实现不需要转换整个查询就足够了。我正在使用http://www-rohan.sdsu.edu/~eckberg/relationalcalculusemulator.html
来检查我的关系演算和将其转换为 sql 查询。
笔记:
如果您在查询中使用含义。
它不支持蕴涵。例如蕴涵可以实现如下。(p==>q) 可以写成 (not p or q) 形式,因为两者在逻辑上是等价的。