自己写的,亲测可用。请给分。
3、已知三个关系模式:
学生 S(S#,SNAME,AGE,SEX),其属性的含义为:学号,姓名,年龄,性别;
学习成绩 SC(S#,C#,GRADE) ,其属性的含义为:学号,课程号,成绩;
课程 C(C#,CNAME,TEACHER),其属性的含义为:课程号,课程名,教师。
(1)请用关系代数表达式描述查询:学号为‘S2’的学生所选课程的课程号。
答: Pi C#(Delta S#=‘S2’(S))其中Pi表示投影,Delta 表示选择
(2)完善下面的SQL语句片断。
答:
CREATE TABLE SC(
S# CHAR(10),
C# CHAR(10),
GRADE NUMBER(2),
primary key (S#,C#), /建立主码约束/
FOREIGN KEY REFERNCES S(S#), /在S#列上建立外码约束/
……
)
(3)用SQL查询块描述下列查询:
学生“李勇”所选选修的课程名。
答: SELECT CCNAME
FROM S, SC, C
WHERE S SNAME='李勇'
AND SS#=SCS#
AND CC#=SCC#;
统计每门课程的选课人数。
答:SELECT CCNAME, COUNT(SS#)
FROM SC, C, S
WHERE CC# = SCC#
AND SCS# = SS#
group by CCNAME;
在学生表中插入数据(‘1001’,‘王勇’,‘男’,19)
答:INSERT INTO S VALUES ('1001','王勇','男',19);
COMMIT;
你提供的信息不全,从第三题开始没办法作答了。。
CREATE TABLE SC
(Sno INT NOT NULL,
Cno NVARCHAR(50) NOT NULL,
Grade NVARCHAR(50) NOT NULL
)
GO
SELECT FROM Course WHERE Cname LIKE 'MIS%' AND LEFT(RIGHT(Cname,2),1)='系'
SELECT COUNT() FROM Course
因为S表和C表两者并没关系,而SC表既关联S表也关联C表,所以要查女生选修了某课必须用SC表。
按你所说的,语句应该为:
select ssname from s,c,sc where ssno=scsno and ccno=sccno and asex='女' and ccname='XXXX课'1insert into student(sno,sname,sex) select ssno,ssname,ssex from sc sc left join s s on ssno=scsnoleft join c c on sccno=ccno where scgrade>=80 and sccno='第一门课程'2delete from sc where grade=0 or grade is null3delete from sc where sno='0001'4update sc set grade=0 where sno in (select scsno from sc sc left join c c on sccno=ccnowhere ccname='数据库应用' and scgrade<60)5update sc set grade=grade105
where sno in(
select scsno
from sc sc
left join s s
on scsno=ssno
where grade<(select avg(grade) from sc)
and sssex='f'
)
6update sc set grade=grade104
where grade>75 and cno='c001'
update sc set grade=grade105
where grade<=75 and cno='c001'
1create table S
(SNO char(10) primary key,
SNAME varchar(20),
AGE int,
SEX char(2)default '男')
2SELECT CNO,CNAME FROM C WHERE TEACHER='LI'
3insert into C values('C01','高等数学','LI')
4SELECT SNO,SNAME FROM S WHERE AGE>21 AND SEX='男'
5select CNAME,TEACHER FROM C INNER JOIN SC ON CCNO=SCCNO WHERE SCSNO='S1'
6SELECT SNAME FROM S
WHERE SEX='男' and SNO in(select SNO from SC inner join
C on SCCNO=CCNO WHERE CTEACHER='LI')
7select CNO,CNAME FROM C
WHERE CNO in(select CNO from SC inner join
S on SCSNO=SSNO WHERE SSNAME='WANG')
8SELECT CNO 课程号,SEX 性别,count() 总人数,AVG(GRADE) 平均成绩 FROM SC INNER JOIN
S ON SCSNO=SSNO group by CNO,SEX
9select SNAME,SNO from S
where SNO in (select SNO FROM SC group by SNO having count(SNO)>=2)
以上就是关于在学生-课程数据库中,有三张表,请用关系代数表达式查询如下问题全部的内容,包括:在学生-课程数据库中,有三张表,请用关系代数表达式查询如下问题、试用SQL查询语句表达学生-课程数据库中3个基本表S,SC,C的查询、数据库的,要查找选修某课程的女学生姓名为什么涉及到了SC表等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)