连接3个表SQL
我尝试解决这个问题很长一段时间,但输出是错误的。谁能帮我解决这个问题吗?我使用的是mysql,所以全连接不起作用。谢谢你们
3 张桌子:
Frequents (attributes: drinker, bar, times_a_week),
Likes (attributes: drinker, beer),
Serves (attributes: bar, beer, price),
这个问题是针对所有经常光顾“每个”酒吧的饮酒者提出的,这些酒吧提供他们喜欢的啤酒
我的答案如下:
SELECT drinker
FROM frequents
WHERE drinker NOT IN (SELECT f.drinker FROM frequents f
JOIN likes l ON f.drinker=l.drinker
LEFT JOIN serves s ON l.beer=s.beer
AND s.bar=f.bar
WHERE s.bar IS NULL)
I am trying to solve this problem for quite some time and the output is wrong. Can anyone help me with this? I am using mysql, so full join doesnt work. Thank yyou
3 tables:
Frequents (attributes: drinker, bar, times_a_week),
Likes (attributes: drinker, beer),
Serves (attributes: bar, beer, price),
The question ask for all the drinkers who frequent "every" bar which serve some beers they like
My answer looks like this:
SELECT drinker
FROM frequents
WHERE drinker NOT IN (SELECT f.drinker FROM frequents f
JOIN likes l ON f.drinker=l.drinker
LEFT JOIN serves s ON l.beer=s.beer
AND s.bar=f.bar
WHERE s.bar IS NULL)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
如果它不起作用,您可以发布一些数据示例吗?
how about this:
if it doesn't work, can you post some example of your data?