34,576
社区成员
发帖
与我相关
我的任务
分享
select distinct t1.name , t2.name from
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t1,
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t2
where t1.id = t2.id and t1.name < t2.name
order by t1.id , t1.name , t2.name
--加个order by
select t1.name , t2.name from
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t1,
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t2
where t1.id = t2.id and t1.name < t2.name
order by t1.id , t1.name , t2.name
--如果A,B和B,A算重复的话,不要,就用t1.name < t2.name
select t1.name , t2.name from
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t1,
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t2
where t1.id = t2.id and t1.name < t2.name
--上面错了,a.id = b.id 改为 t1.id = t2.id
select t1.name , t2.name from
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t1,
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t2
where t1.id = t2.id and t1.name <> t2.name
select t1.name , t2.name from
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t1,
(select a.name , b.id from 学生表 a , 选课表 b where a.id = b.sid ) t2
where a.id = b.id and t1.name <> t2.name
select t1.name , t2.name from
(select a.name from 学生表 a , 选课表 b where a.id = b.sid and b.id = '某课程号') t1,
(select a.name from 学生表 a , 选课表 b where a.id = b.sid and b.id = '某课程号') t2
where t1.name <> t2.name