白日梦想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 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算