初学者请教一道基础SQL查询习题
sql吧
全部回复
仅看楼主
level 1
查询既选修了"3"号又选修了"4"号课程的学生姓名、课程名及成绩。表如图
2019年10月17日 09点10分 1
level 2
用between an试试
2019年10月17日 11点10分 2
还是想不出来
2019年10月17日 14点10分
level 3
select s.sname,t.* from student s,
(select t1.sid,t1.cname,t1.score,t2.score from(
(select sc.sid,sc.cid,c.cname,sc.score from sc inner join course c on c.cid=sc.cid where sc.cid=3) t1,
(select sc.sid,sc.cid,c.cname,sc.score from sc inner join course c on c.cid=sc.cid where sc.cid=4) t2
where t1.sid=t2.sid) t
where s.sname=t.tid
2019年10月18日 05点10分 3
最后一个是sid写错了。
2019年10月18日 05点10分
好的,我明天试试,还是不行再继续问
2019年10月19日 16点10分
你这个有点看不懂啊,我还没学inner join,还有其它的办法吗?
2019年10月22日 08点10分
试试这个 SELECT * FROM student s,Course c, cs WHERE s.sru = cs.sru AND c.cro=cs.cro AND cs.cro IN(3,4) HAVING COUNT(cs.sur)>1
2019年10月22日 09点10分
level 3
就是先把1课程的学生id求出,2课程学生id求出,关联相等,就是都有的,然后再关联得到其他的信息
2019年10月18日 05点10分 4
level 1
这是我现在写的,我能做到查询出选了"3"号课又选了“4”号课的学生姓名,和这两个课的成绩,但是课程名不知道怎么写,我试了好多种写法都不行
2019年10月22日 09点10分 5
你这写法 ,三张表关联有问题的,至少要将表关联关系先组合好,在加查询条件
2019年10月22日 09点10分
level 1
我感觉已经接近了,但是成绩我还是试了好多写法都不对
2019年10月22日 11点10分 6
我感觉问题出在Grade的写法上
2019年10月22日 11点10分
level 1
select sname,cname,grade from student s,course c,sc
where s.sno = sc.sno and c.cno =sc.con and sc.con in (3,4) and
s.sno in
(select sno from sc where con in (3,4) group by sno having count(sno)>1)
2019年10月22日 14点10分 7
对就是这样,仿照你的做出来了,谢啦
2019年10月22日 15点10分
level 8
挺好写的,写那么复杂干嘛
2019年10月22日 23点10分 8
刚学,写的时候思路不清晰,脑子里一团浆糊
2019年10月23日 12点10分
level 2
这图片怎么看得清楚的
2019年10月24日 09点10分 9
1