0
点赞
收藏
分享

微信扫一扫

《数据库概论》实验(3)-交互式SQL--简单查询

#① 查询计算机系学生的学号、姓名、性别和出生日期。

select sno,sname,ssex,sbirthday from students where sdept ='计算机';

#② 查询姓“李”的学生的学号和姓名。

select sno,sname from studentsWHERE sname like '李%';

#③ 查询课程表中先行课为空的课程名。

 select cname from courses where precno is null;

#④ 查询考试成绩有不及格的学生的学号。

select sno from sc where grade<60;

#⑤ 求选修了C1 课程或C2 课程的学生的学号及成绩。

 select sno,grade from sc where cno=('C02' or 'c01');

#⑥ 查询全体计算机系学生的姓名及其年龄。

 select sno,timestampdiff(YEAR,SBirthday,curdate()) AS SAVEPOINT from students where sdept ='计算机';

#⑦ 查询计算机系在1986-1987 年之间出生的学生的姓名。

 select sname from students where sbirthday between '1986-1-1' and '1987-12-31';

#⑧ 查询姓“李”且姓名为3个汉字的学生学号和姓名。

select sno,sname from students WHERE sname like'李__';

#⑨ 查询选修了两门以上课程的学生学号与课程数。

select sno,count(*)from sc group by sno having count(sno)>=2;

#⑩ 查询选修课程数大于等于2 的学生的学号、平均成绩和选课门数,并按平均成绩降序排列。

select sno,avg(grade) ,count(cno) 

    from sc 

 group by sno 

 having count(cno)>=2

  order by avg(grade) desc;

举报

相关推荐

0 条评论