一个sql 语句问题 请教 ···

fx397993401 2010-04-04 11:04:43
#0.基本单表查询所有
学生表
mysql> select * from student;
+-----------+-------+------+------+------+
| sno | sname | ssex | sage | sclg |
+-----------+-------+------+------+------+
| 200215121 | 李勇 | 男 | 20 | cs |
| 200215122 | 刘晨 | 女 | 21 | cs |
| 200215123 | 王敏 | 男 | 25 | ma |
| 200215125 | 张立 | 男 | 20 | is |
+-----------+-------+------+------+------+

选课表
mysql> select * from sc;
+-----------+-----+-------+
| sno | cno | grade |
+-----------+-----+-------+
| 200215121 | 1 | 92 |
| 200215121 | 2 | 85 |
| 200215121 | 3 | 88 |
| 200215122 | 2 | 90 |
| 200215122 | 3 | 80 |

+-----------+-----+-------+
课程表
mysql> select * from course;
+-----+----------+------+---------+
| cno | cname | cpno | ccredit |
+-----+----------+------+---------+
| 1 | 数据库 | 5 | 4 |
| 2 | 数学 | NULL | 4 |
| 3 | 信息系统 | 1 | 4 |
| 4 | 操作系统 | 6 | 4 |
| 5 | 数据结构 | 7 | 4 |
| 6 | 数据处理 | NULL | 4 |
| 7 | C语言 | 6 | 4 |
+-----+----------+------+---------+

题目:查询至少选修了学生200212122选修的全部课程的学生姓名.
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
小小小小周 2010-04-05
  • 打赏
  • 举报
回复
select distinct a.sno,a.sname from student a,sc b
where a.sno=b.sno
and exists
(select b.cno from student a,sc b
where a.sno=b.sno
and a.sno=200215122)
and a.sno <>200215122
小小小小周 2010-04-05
  • 打赏
  • 举报
回复
有关连表查询的方法,找出相关的关联列就可以了
ACMAIN_CHM 2010-04-05
  • 打赏
  • 举报
回复
建议你先自己试着解释一下这个sql,否则别人也根本不知道你目前已经懂了什么,到什么层次,到底是哪儿不懂。

写出你自己的理解,然后让别人来看你的理解是否正确。 否则别人解释过简单你还是理解不了,解释得过细,可能又是根本不必要。
fx397993401 2010-04-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 acmain_chm 的回复:]

SQL code
select sname
from student s
where not exists (
select 1 from sc where sno='200212122' and cno not in (select cno from sc where sno=s.sno)
)
[/Quote]
能解释下么 不是很懂
ACMAIN_CHM 2010-04-04
  • 打赏
  • 举报
回复
select sname
from student s
where not exists (
select 1 from sc where sno='200212122' and cno not in (select cno from sc where sno=s.sno)
)

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧