学号(ID) 科目(Name) 分数(Number)
1 数学 68
1 英语 22
1 语文 452 数学 78
2 英语 90
2 语文 883 数学 66
3 英语 78
3 语文 22把这几个学生的按总分按降序排列,查询结果学号不出现重复数据如学号 总分
1 135
1 数学 68
1 英语 22
1 语文 452 数学 78
2 英语 90
2 语文 883 数学 66
3 英语 78
3 语文 22把这几个学生的按总分按降序排列,查询结果学号不出现重复数据如学号 总分
1 135
insert into tb select 1,'数学',68
insert into tb select 1,'英语',22
insert into tb select 1,'语文',45
insert into tb select 2,'数学',78
insert into tb select 2,'英语',90
insert into tb select 2,'语文',88
insert into tb select 3,'数学',66
insert into tb select 3,'英语',78
insert into tb select 3,'语文',22
go
select id,sum(number)as number from tb group by id order by 2 desc
go
drop table tb
/*
id number
----------- -----------
2 256
3 166
1 135(3 行受影响)*/