房天下 > 房天下问答 > 业主生活 > 其他
  • 帮忙做下数据库题目``

    某校教学管理系统中三个关系表:学生(学号,姓名,年龄,性别,所在系)课程(课程号,课程名,开课系,任课老师)成绩(学号,课程号,成绩)一、创建这三个表,并给出主键和外键二、用SQL语句完成下列操作: 1、查询刘老师所授课程的课程号和课程名 2、查询至少修刘老师所授一门课中的女学生的姓名 3、查询王乐同学不学的课程号 4、统计有学生修读的课程门数 5、求修读C4课程的平均成绩 6、刘老师所带课程的每门课的平均成绩 7、查询姓名以王打头的所有学生的姓名和年龄 8、求年龄大于所有女同学的男同学的姓名和年龄 9、往学生表中插入(‘009’,‘吴’,18) 10、删除成绩表中无成绩的元组 11、把选修“数据库”不及格的成绩全部改为0 12、把低于总平均成绩的女同学的成绩提高5%

    提问者:bxdc

    发布于2010-11-24

共1个回答
  • merry_leung 丨Lv 2
    -- 一题create table s--学生表(sno char(8) primary key,--学号sname char(10) ,--姓名sage int ,--年龄ssex char(2),--性别sdept char(20))--所在系create table c--课程表(cno char(4) primary key,--课程号cname char(20),--课程名c_dept char(20),--开课系teacher char(10))--老师create table sc--成绩表(sno char(8) not null,--学号cno char(4) not null,--课程号grade int ,--成绩constraint PK_sc primary key(sno,cno),--主键constraint PK_s_sno foreign key(sno) references s(sno),--外键constraint FK_c_cno foreign key(cno) references c(cno))--外键--二题--1select cno,cnamefrom cwhere teacher='刘'--2select snamefrom swhere ssex='女'and sno in (select snofrom scwhere cno in(select cnofrom cwhere teacher='刘'))--3select cnofrom cwhere not exists(select * from s,sc where s.sno=sc.sno and sc.cno=c.cno and sname='王乐')--4select count(distinct Cno) as 课程门数from sc--5select avg(grade)from scwhere cno='c4'--6select c.cno,avg(grade) as avg_gradefrom sc,cwhere sc.cno=c.cno and teacher='刘'group by c.cno--7select sname,sagefrom swhere sname like'王%'--8select sname,sagefrom swhere ssex='男' and sage>all(select sagefrom swhere ssex='女')--9insert into s(sno,sname,sage)values('009','吴',18)--10delete from scwhere grade is null--11update scset grade=0where cno in (select cnofrom cwhere cname='数据库')and grade<60--12update scset grade=grade*1.05where sno in(select sno from s where ssex='女' and grade<(select avg(grade) from sc))
    +1 2010-11-24 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。