用SQL查询平均成绩高于90分的同学的学号、姓名及其平均成绩,并按成绩由高到低排序
2013-11-06
展开全部
create database StudentsDB
go
use StudentsDB
go
if exists(select name from sysobjects where name='Student' and xtype='u')
drop table Student
go
create table Student
(
StuID int,
name varchar(10),
)
go
insert into Student(StuID,name) values(1,'aa')
insert into Student(StuID,name) values(2,'bb')
insert into Student(StuID,name) values(3,'cc')
insert into Student(StuID,name) values(4,'dd')
go
create table CJ
(
StuID int,
km varchar(10),
kmcj float
)
go
insert into CJ(StuID,km,kmcj) values(1,'yw',78.5)
insert into CJ(StuID,km,kmcj) values(1,'sx',86)
insert into CJ(StuID,km,kmcj) values(1,'yy',69.7)
insert into CJ(StuID,km,kmcj) values(2,'yw',91)
insert into CJ(StuID,km,kmcj) values(2,'sx',79)
insert into CJ(StuID,km,kmcj) values(2,'yy',66)
insert into CJ(StuID,km,kmcj) values(3,'yw',81)
insert into CJ(StuID,km,kmcj) values(3,'sx',90)
go
select s.StuID,s.name,AVG(c.kmcj) as avgs from Student s join CJ c
on s.StuID = c.StuID group by s.StuID,s.name having AVG(c.kmcj)>80 order by avgs
go
use StudentsDB
go
if exists(select name from sysobjects where name='Student' and xtype='u')
drop table Student
go
create table Student
(
StuID int,
name varchar(10),
)
go
insert into Student(StuID,name) values(1,'aa')
insert into Student(StuID,name) values(2,'bb')
insert into Student(StuID,name) values(3,'cc')
insert into Student(StuID,name) values(4,'dd')
go
create table CJ
(
StuID int,
km varchar(10),
kmcj float
)
go
insert into CJ(StuID,km,kmcj) values(1,'yw',78.5)
insert into CJ(StuID,km,kmcj) values(1,'sx',86)
insert into CJ(StuID,km,kmcj) values(1,'yy',69.7)
insert into CJ(StuID,km,kmcj) values(2,'yw',91)
insert into CJ(StuID,km,kmcj) values(2,'sx',79)
insert into CJ(StuID,km,kmcj) values(2,'yy',66)
insert into CJ(StuID,km,kmcj) values(3,'yw',81)
insert into CJ(StuID,km,kmcj) values(3,'sx',90)
go
select s.StuID,s.name,AVG(c.kmcj) as avgs from Student s join CJ c
on s.StuID = c.StuID group by s.StuID,s.name having AVG(c.kmcj)>80 order by avgs
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-06
展开全部
select 学号,姓名,avg(成绩) as '平均成绩' from 学生成绩表 where avg(成绩) > 90 order by avg(成绩) desc这样试试...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询