白日梦想jun 2016-05-07 03:21 采纳率: 100%
浏览 1218

SQL exist与=,in的问题 谢谢指导

//是不是子查询是=就不可以用exists呢?但是=也可以换成In啊,用in的地方不是就可以换成exists吗?但是这里结果不对
student(sno,sname,sdept);course(cno,cname,ccredit);sc(sno,cno,grade)

1、找出学分为4分以上的课程的选修情况,列出学号,课程名,成绩
    select sno,cname,grade from sc,course 
                            where sc.cno = course.cno and
                            sc.cno in(select cno from course where ccredit >4)

select sno,cname,grade from sc,course 
                        where  sc.cno = course.cno and
                        exists(select *from course where sc.cno = cno and ccredit >4)
    //这里in换成exists是对的

2、查询和数据结构相同学分的课程
select cno,cname,ccredit from course 
                    where ccredit=(select ccredit from course where cname = '数据结构')
                    and cname <> '数据结构';  //这里返回了与数据结构相同学分的另外的课

--有问题                     
select cno,cname,ccredit from course x
                    where exists(select * from course where cname = '数据结构' and x.cno = cno);  //但是这里只返回了数据结果,没有其余的课
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料