看起来你想要带有提醒的关系划分。
SQL小提琴
Oracle 11g R2 模式设置:
create table YourTable
(
Name varchar(10),
Lang varchar(10),
primary key (Name, Lang)
);
insert into YourTable values('John', 'English');
insert into YourTable values('John', 'French');
insert into YourTable values('John', 'Spanish');
insert into YourTable values('John', 'Swedish');
insert into YourTable values('Mark', 'English');
insert into YourTable values('Mark', 'French');
insert into YourTable values('Mark', 'Spanish');
insert into YourTable values('Peter', 'English');
insert into YourTable values('Peter', 'French');
查询 1:
select T1.Name
from YourTable T1
inner join YourTable T2
on T1.Lang = T2.Lang
where T2.Name = 'Mark'
group by T1.Name
having count(T1.Lang) = (select count(Lang)
from YourTable
where Name = 'Mark')
结果:
| NAME |
--------
| John |
| Mark |