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)
数据库练习二
最新推荐文章于 2022-04-06 22:53:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)