关于数据库的语句该怎样写·

来源:百度知道 编辑:UC知道 时间:2024/06/24 06:28:42
1.统计每个学生的选课数量 (结果显示学号和选课数量,按选课数量升序排列)
2.统计信息系每个学生的选课数量 (结果显示学号、姓名和选课数量,按选课数量升序排列)
3.统计至少选了4门课的每个学生的选课数量(结果显示学号、姓名和选课数量,按选课数量升序排列)
4.统计每个课程的最高分 (结果显示课程编号和最高分,按分数降序排列)
5.统计学分大于等于3分的每个课程的最高分(结果显示课程编号、课程名和最高分,按分数降序排列)
5.统计最高分大于90的每个课程的最高分 (结果显示课程编号、课程名和最高分,按分数降序排列)
create table student(
sno char(5) primary key,
sname varchar(20),
ssex bit,
sage numeric(2,0),
sdept varchar(20));
create table course(
cno char(3) primary key,
cname varchar(16),
cpno char(23),
ccredit numeric(1,0));
create table sc(
sno char(5),
cno char(3),
grade numeric(5,1),
primary key (sno,cno),
foreign key(sno) references student(sno),
foreign key(cno) references course(cno));

create table student(
sno char(5) primary key,
sname varchar(20),
ssex bit,
sage numeric(2,0),
sdept varchar(20)
);

create table course(
cno char(3) primary key,
cname varchar(16),
cpno char(23),
ccredit numeric(1,0)
);

create table sc(
sno char(5),
cno char(3),
grade numeric(5,1),
primary key (sno,cno),
foreign key(sno) references student(sno),
foreign key(cno) references course(cno)
);

1.统计每个学生的选课数量 (结果显示学号和选课数量,按选课数量升序排列)
select sno, count(*) as number from sc group by sno order by number

2.统计信息系每个学生的选课数量 (结果显示学号、姓名和选课数量,按选课数量升序排列)
select sc.sno, stu.sname, a.number from sc,student as stu,(select sno,count(*) as number from sc,student where sc.sno in (select sno from student where sdept = "信息系") group by sno) as a order by number

3.统计至少选了4门课的每个学生的选课数量(结果显示学号、姓名和选课数量