使用以下数据库架构,找到仅提供Joe喜欢的啤酒的酒吧
Beers(name, manf)
Bars(name, addr, license)
Drinkers(name, addr, phone)
Likes(drinker, beer)
Sells(bar, beer, price)
Frequents(drinker, bar)
这是我的尝试:
SELECT b.name
FROM bars b
WHERE NOT EXISTS
(SELECT l.beer
FROM likes l
WHERE l.drinker = 'joe' AND NOT EXISTS
(SELECT *
FROM sells s
WHERE l.beer = s.beer AND b.name = s.bar))
我的尝试返回了供应啤酒乔喜欢的酒吧,而不是仅供应他喜欢的啤酒的酒吧。 关于我出错的地方的任何帮助都会有所帮助
答案 0 :(得分:0)
可能是这些酒吧
select bar
from Sells not in (
select bar
from Sells
where beer not in (select beer from likes where drinker = 'joe')
)