选出与“xx”这个人所选的课程完全相同的人的姓名

解决方案 »

  1.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  2.   

    有三个表
    S表示学生信息的表,Sno学号Sname学生姓名Sage年龄Ssex性别Sdept专业
    C课程信息表,Cno课程号Cname课程名称Credit学分
    SC学生选课表,Sno学号,Cno课程编号,Grade成绩create table S
    (Sno int not null unique,
    Sname varchar(20) not null,
    Sage int check(Sage between 1 and 100),
    Ssex varchar(20) check(Ssex in('男','女')),
    Sdept varchar(20) not null,
    constraint S_PK primary key(Sno));create table C
    (Cno int not null unique,
    Cname varchar(20) not null,
    Ccredit int,
    constraint C_PK primary key(Cno));create table SC
    (Sno int not null unique,
    Cno int not null unique,
    Grade int check(Grade between 0 and 100),
    constraint CS_PK primary key(Sno,Cno),
    constraint CS_FK1 foreign key(Sno) references S(Sno),
    constraint CS_FK2 foreign key(Cno) references C(Cno));
    K, 0 rows affected (0.03 sec)
    要求写一sql语句:
    列出与“张三”这个人所选课程完全相同的人的姓名
    比如张三选了“数据结构”和“C++”以及XXX很多课程,某人和张三选的课程完全相同的话列出这些人的姓名
      

  3.   

    select Sname
    from S
    where Not Exists (Select 1 from SC where Sno=(select Sno from S where Sname='张三') and Cno not in (select SC where Sno=S.Sno))
    and Not Exists (Select 1 from SC where Sno=S..Sno and Cno not in (select SC where Sno=(select Sno from S where Sname='张三')))