您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页SQL查询语句

SQL查询语句

来源:纷纭教育


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 from student;

6、查询Student表中前三名学生的学号和姓名。 select top 3 sno,sname from student;

7、查询Student表中所有学生的姓名和出生年份用别名表示。

select sname,2011-sage from student;

8、查询Sc 表中所有选课学生的学号。 select distinct sno from student;

9、查询所有男生在20岁以下的学生的姓名,年龄。 select sname,sage form student

where ssex=’男’ and sage<20; 10、查询所有及格学生的学号。 select sno

from sc

where grade>60;

11、查询CS系90年以前出生学生的学号和姓名。 select sno,sname from student

where sdept=’CS’ and 2011-sage <1990;

12、用between和and,查询70~80分学生的学号和课程号。 select sno,cno from sc

where grade between 70 and 80;

13、查询19~1992年出生的学生的姓名和性别。 select sname,ssex from student

where 2011-sage between 19 and 1992; 14、查询成绩不在70~80分的学生的学号。 select sno from sc

where grade not between 70 and 80; 15、查询70.80.90分的学生的学号。 select sno from sc

where grade in (70,80,90);

16、用in查询19,1987年出生的学生的姓名和学号。 select sname,sno from student

where 2011-sage in(19,1987);

17、查询学分不是3分和5分的课程号和课程名 select cno,cname from course

where ccredit not in (3,5); 18、查询所有2002级学生的所有资料 select * from student

where sno like’2002%’;

19、查询姓刘,张的学生的姓名和姓别 select sname,ssex from student

where sname like ‘[刘,张]%’;

20、查询课程名含“数据”的课程名和学分。 select cname,ccredit from course

where cname like ‘%数据%’;

21、查询所有课程号为“2”的学生的学号和成绩。 selelct sno,grade

from sc

where cno=’2’ and grade is not null;

22、查询所有参加课程号为“1”的考试的学生的学号。 selelct sno from sc

where cno=’1’ and grade is null;

23、查询所有2002级男生和MA系的学生的学号和姓名。 select sno,sname from student

where sno like ‘2002%’ and ssex=’男’ or sdept=’MA’;

24、查询所有学分为“4”的和先行课程号为“6”的课程号和课程名。 select cno,cname from course

where cpon=6 or ccredit=4;

25、查询所有CS系学生的名单,性别升序,年龄降序排列。 select * from student where sdept=’CS’ order by ssex,sage desc;

26、查询所有2002级学生选择考试情况,课程号升序,成

绩降序排列。 select cno,grade from sc

where sno=’2002%’ order by cno,grade desc; 27、统计2号课程总人数。 select count(distinct sno) from sc

where cno=’2’;

28、统计CS系年龄在20岁以上男生的平均年龄。 select avg(sage) from student

where sdept=’CS’ and ssex=’男’ and sage>20; 29、统计选修1号课程的最高成绩,最低成绩。 select max (grade),min (grade) from sc

where cno=’1’;

30、求各系学生的平均年龄。 select avg(sage) from student group by sdept;

31、求每门课程的平均成绩和最高成绩。

select avg(grade),max(grade) from sc group by cno;

32、查询各系男生的总人数及平均年龄。 select count(*),avg(sage) from student where ssex=’男’;

33、查询所有的及格学生各科的总成绩和平均成绩。 select sum(grade),avg(grade) from sc

where grade>=60 group by cno;

34、查询选择3门以上课程学生的学号。 select sno from sc group by sno having count(*)>3;

35、查询每门的最高成绩并按课程号降序排列。 select max(grade),cno from sc group by cno order by cno desc;

36、查询CS系学生的考试情况。 select sc. * from student,sc

where student.sno=sc.sno and sdept= ‘CS’; 37、查询所有男生选修2号课程的学号姓名成绩。 select student.sno,sname,grade from student ,sc

where student.sno=sc.sno and ssex=’男’ and cno=’2’;

38、查询选修数据库的学生的学号和成绩 select sno,grade from course,sc

where course.cno=sc.cno and cname=’数据库’; 39、查询选修操作系统这门课学生的姓名,学号,成绩。 select sname,student.sno,grade from student,crouse,sc

where student.sno=sc.sno and sc.cno=course.cno and cname=’操作系统’;

40、查询所有CS系学生选修1号课程的学号和成绩降序排列。

select student.sno,grade from student,sc

where student.sno=sc.sno and sdept=’CS’ and cno=’1’

order by grade desc;

41、查询选修2号课程学生的学号,姓名,课程号。 select student.sno,sname,grade,cname from student,sc,course

where student.sno=sc.sno and sc.cno=course.cno and sc.cno=’2’;

42、查询1990年以前出生男生选修1号课程的姓名成绩。 select sname,grade from student,sc,course

Where student.sno=sc.sno and sc.cno=course.cno and 2011-sage<1990 and ssex=’男’ and sc.cno=’1’; 43、查询学分>5的成绩在80分以上的所有选课学生的姓名和成绩降序排列。 select sname,grade from student,sc,course

where student.sno=sc.sno and sc.cno=course.cno and ccredit>5 and grade>80 order by grade desc;

44、查询CS系及格学生的姓名,成绩,课程号(分别用内左右全写)。

select sname,grade,cno from student,sc where

student.sno=sc.sno

and

grade>=60

and

sdept=’CS’; 内连接 select sname,grade,cno from student,sc

where student inner join sc on (student.sno=sc.sno and grade>=60 and sdept=’CS’); 左连接

select sname,grade,cno from student,sc

where student left join sc on (student.sno=sc.sno and grade>=60 and sdept=’sc’); 右左连接

select sname,grade,cno from student,sc

where student right join sc on (student.sno=sc.sno and grade>=60 and sdept=’sc’); 45、查询1986年出生学生的选课情况。 select sc.* from sc

where sc.sno in(select sno

from student

where 2011-sage=1986);

46、查询学分>5课程的选课情况。 select sc.* from sc

where sc. cno in( select cno

from course where ccredit >5);

47、查询选修了操作系统这门课学生的学号,姓名,系别。 select student.sno,sname,sdept from student

where student.sno in(select sc.sno from sc,course

Where sc.cno=course.cno and cname=’操作系统’); 48、查询选修了数据库这门课并且成绩>80分学生的学号和姓名。

select student.sno,sname from student

where sno in (select sno

from sc, course

where sc.cno=course.cno and cname=’数据

库’ and grade>80 );

49、查询所有学生大于其总平均成绩的课程号,学号,成绩。 select cno,sno,grade from sc

where grade> in (select avg(grade)

from sc

group by sc.sno );

50、查询选修1号课程大于选修2号课程的平均成绩的学号,成绩。

select sno,grade from sc

where grade>(select avg(grade) from sc

where cno=’2’) and cno=’1’;

51、查询选修1号课程比选修2号课程任意学生成绩低的学生的学号和成绩。 select sno,grade from sc

where gradefrom sc

where cno=’2’)

and cno=’1’;

52、查询选修1号课程比选修2号课程所有学生成绩高的学生的学号和成绩。 select sno,grade from sc

where grade>all(select grade

from sc

where cno=’2’) and cno=’1’;

53、查询CS系1986年以后出生的学生学号,姓名与1号课程且成绩大于60分学生的学号,姓名的并,交,差。 select sno,sname from student

where 2011-sage>1986 and sdept=’cs’ union

select sno,sname from student,sc

where student.sno=sc.sno and cno=’1’ and grade>60;

电子0901

张雄 0903024114

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务