标签:sname sno 数据库 练习 student sc where select
use Stu; #(1)查询全体学生的学号和姓名。 select sno,sname from student; #(2)查询全体学生的详细记录。 select * from student; #(3)查询全体学生的姓名和出生年份。 select sname,2020-sage from student; #(4)查询选修了课程的学生的学号。 select distinct sno from sc; #(5)查询计算机系的学生的姓名。 select sname from student where sdept="计算机系"; #(6)查询年龄在20岁以下的计算机系的学生的学号和年龄。 select sno,sage from student where sdept="计算机系" and sage<20; #(7)查询年龄在20—22岁的学生的学号。 select sno from student where sage between 20 and 22; #(8)查询信息系、计算机系和外语系的学生的信息。 select * from student where sdept in('计算机系','信息系','外语系'); #(9)查询姓“王”的学生的信息。 select * from student where sname like '王%'; #(10)查询选修了3号课程的学生的学号及成绩,结果按分数的降序排列。 select sno,grade from sc where cno='3' order by grade DESC; #(11)查询学生总人数。 select count(distinct sno)from student; #(12)查询选修1号课程的学生的最高分。 select MAX(grade) from sc where cno='1'; #(13)查询选修了3门以上课程的学生的学号。 select sno from sc group by sno having count(*)>3; #(14)查询每个学生及其选修课程的情况。 select student.*,sc.* from student,sc where student.sno=sc.sno; #(15)查询选修2号课程且分数在90分以上的所有学生。 select student.sno,sname from student,sc where student.sno=sc.sno and sc.cno='2' and sc.grade>90; #(16)查询每个学生的学号、姓名、选课名及成绩。 select student.sno,sname,sc.cname,grade from student,sc,course where student.sno=sc.sno and sc.cno=course.cno; #(17) 查询与“张三”在同一系的学生。 select s1.sno,s1.sname,s1.sdept from student s1,student s2 where s1.sdept=s2.sdept and s2.sname='张三'; #(18) 查询选修了课程名为“数据库”的学生学号和姓名。 select student.sno,sname from student,sc,course where student.sno=sc.sno and sc.cno=course.cno and course.cname='数据库'; #(19) 查询没有选修1号课程的学生的姓名。 select sname from student where not exists (select * from sc where sc.sno=student.sno and cno='1'); #(20) 查询选修了所有课程的学生的姓名。 select sname from student where not exists (select * from course where not exists (select * from sc where sno=student.sno and cno=course.cno));
标签:sname,sno,数据库,练习,student,sc,where,select 来源: https://www.cnblogs.com/Lorrained/p/14771536.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。