首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单sql语法,求回帖!求解决!

2012-03-06 
简单sql语法,求回帖!求解决!在线等!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!SQL co

简单sql语法,求回帖!求解决!在线等!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

SQL code
create table StuScore(ID int identity(1,1),[Name] varchar(20),Class varchar(20),Score int)truncate table StuScoreinsert into StuScore values('张春明','语文',89)insert into StuScore values('张春明','数学',97)insert into StuScore values('刘菲','数学',97)insert into StuScore values('刘菲','英语',20)insert into StuScore values('刘菲','语文',70)insert into StuScore values('吴京','语文',91)insert into StuScore values('吴京','英语',96)insert into StuScore values('袁磊','数学',84)insert into StuScore values('袁磊','英语',96)select * from StuScore


Ⅰ、对全体学生总成绩进行排序
Ⅱ、对全体学生单科成绩进行排序
(
排序要求:
a、必须使用排序函数;
b、如果成绩相同,不并排,按顺序[格式如:1、2、3];
c、如果成绩相同,并排,跳序排列[格式如:1、2、2、4];
d、如果成绩相同,并排,不跳序[格式如:1、2、2、3];
)


[解决办法]
SQL code
select *,ROW_NUMBER()over( ORDER BY 總分 desc) AS 名次 from (select [Name],SUM(Score) AS 總分 FROM StuScore GROUP BY [Name])tselect *,DENSE_RANK()over(ORDER BY 總分 desc) AS 名次 from (select [Name],SUM(Score) AS 總分 FROM StuScore GROUP BY [Name])tselect *,RANK()over(ORDER BY 總分 desc) AS 名次 from (select [Name],SUM(Score) AS 總分 FROM StuScore GROUP BY [Name])t 

热点排行