Relational division in mysql without aggregrate functions?

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

I want to implement a simple relational division in mysql with where exists or where not exists.I don't want to use any of the aggregrate functions and also don't want to use where in or where not in clauses.I am trying to write relational algebra and relational calculus queries for the same so it would be easy if I do it this way.

For example:

GID  PID  TEAM  101   1    X  201   2    X  301   3    X  101   4    Y  201   5    Y  101   6    Z 

The answer is GID,TEAM/GID which gives X as the answer.I want to know how to implement this is mysql with where exists or not exists.

回答1:

What you need is simple codd's relational division.

select distinct p.team from player p  where not exists (select * from player p1  where not exists (select * from player p2  where  p.team=p2.team  and  p2.gid=p1.gid)) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!