1、SQ语言的简单语句1、查询Student表中所有学生的姓名,学号及系别。select sname,sno,sdept from student;2、查询Student表中所有学生的详细记录。select * from student;3、查询Student表中所有学生的名单。select sname from student;4、查询Student表中所有学生的姓名及出生年份。select sname,2011-sage from student;5、查询Student表中所有学生的姓名,年龄,系别并插入sdept is select sname,sage,sdept is,sdept fro
2、m student;6、查询Student表中前三名学生的学号和姓名。select top 3 sno,sname from student;7、查询Student表中所有学生的姓名和出生年份用别名表示。Select sname 姓名,2011-sage,出生年份form student;8、查询Sc 表中所有选课学生的学号。Select distinct sno from student;9、查询所有男生在20岁以下的学生的姓名,年龄。Select sname,sageform studentwhere ssex=男 and sage60;11、查询CS系90年以前出生学生的学号和姓名。se
3、lect sno,snamefrom studentwhere sdept=cs and year(出生年)20;29、统计选修1号课程的最高成绩,最低成绩。Select count(max (grade),min(grade)From scWhere cno=1;30、求各系学生的平均年龄。Select avg(age)From student group by sdept;31、求每门课程的平均成绩和最高成绩。Select avg(grade),max(grade)From scgroup by cno;32、查询各系男生的总人数及平均年龄。Select count(*),avg(age)
4、From studentWhere ssex=“男”; 33、查询所有的及格学生各科的总成绩和平均成绩。Select sum(grade),avg(grade)From scWhere grade=60Group by cno;34、查询选择3门以上课程学生的学号。Select snoFrom scGroup by snoHaving count(*)3;35、查询每门的最高成绩并按课程号降序排列。Select max(grade),cnoFrom scGroup by cnoOrder by cno DESC; 36、查询CS系学生的考试情况。Select sc *From student,
5、scWhere student.sno=sc.sno and sdep= cs;37、查询所有男生选修2号课程的学号姓名成绩。Select sno,sname,gradeFrom student ,scWhere student.sno=sc.sno and ssex=男 and cno=2;38、查询选修数据库的学生的学号和成绩Select sno,gradeFrom course,scWhere o=o and cname=数据库;39、查询选修操作系统这门课学生的姓名,学号,成绩。Select sname,sno,gradeFrom student,crouse,scWhere stud
6、ent.sn=sc.sno and o=course,cno and cname=操作系统; 40、查询所有CS系学生选修1号课程的学号和成绩降序排列。Select sno,gradeFrom student,scWhere student.sno=sc,sno and sdept=sc and cno=1Order by grade DESC;41、查询选修2号课程学生的学号,姓名,课程号。Select sno,sname,grade,cnameFrom student,sc,courseWhere student,sno=sc,sno and o=course,cno and cno=2;
7、42、查询1990年以前出生男生选修1号课程的姓名成绩。Select sname,gradeFrom student,sc,courseWhere student.sno=sc.sno and sc,cno=o and year(出生年)5的成绩在80分以上的所有选课学生的姓名和成绩降序排列。Select sname,gradeFrom student,sc,courseWhere student.sno=sc.no and sc.no=o ccredit5 and grade80Order by grade desc;44、查询CS系及格学生的姓名,成绩,课程号(分别用内左右全写)。Sele
8、ct sname,grade,cnoFrom student,scWhere student.sno=sc.sno and grade=60 and sdept=sc; 内连接Select sname,grade,cnoFrom student,scWhere student join sc on (student.sno=sc.sno and grade=60 and sdept=sc); 全连接Select sname,grade,cnoFrom student,scWhere student left join sc on (student.sno=sc.sno and grade=60
9、 and sdept=sc); 左连接Select sname,grade,cnoFrom student,scWhere student right join sc on (student.sno=sc.sno and grade=60 and sdept=sc); 右连接45、查询1986年出生学生的选课情况。Select *From scWhere sno in(selelct snoFrom student Where 2011-sage=1986);46、查询学分5课程的选课情况。Select *From scWhere cno in( select cnoFrom courseWh
10、ere ccredit 5);47、查询选修了OS这门课学生的学号,姓名,系别。Select sno,sname,sdeptFrom studentWhere sno in(select snoFrom sc,courseWhere o=o and cname=操作系统);48、查询选修了数据库这门课并且成绩80分学生的学号和姓名。Select sno,snameFrom studentWhere sno in (select snoFrom sc courseWhere o=o and cname=数据库 and grade80 );49、查询所有学生大于其总平均成绩的课程号,学号,成绩。S
11、elect cno,sno,gradeFrom scWhere grade (select sum(grade) From sc Where sum(grade) in (select avg(grade) From sc Where gradegroup by sno );50、查询选修1号课程大于选修2号课程的平均成绩的学号,成绩。Select sno,gradeFrom scWhere grade(select51、查询选修1号课程比选修2号课程任意学生成绩低的学生的学号和成绩52、查询选修1号课程比选修2号课程任意学生成绩高的学生的学号和成绩53、查询CS系1986年以后出生的学生学号,姓名与1号课程且成绩大于60分学生的学号,姓名的并交差
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1