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

跑求:死了:小弟我想得到一个表值不是最大记录 怎么做

2012-01-30 
跑求:急死了:我想得到一个表值不是最大记录如何做?我只知道selectmax(******)可以得到最大值但是我想得到

跑求:急死了:我想得到一个表值不是最大记录 如何做?
我只知道   select   max(******)   可以得到最大值   但是我想得到   不是最大值的如何做?  
id     course         成绩
001     英语           80
001     英语           65
001     英语           90
我就想得到
id     course         成绩
001     英语           80
001     英语           65
帮忙啊!谢谢了

[解决办法]

2005:
create table ta(id int,name int)
insert ta select 1,2 union all select 1,3


select *,row=ROW_NUMBER () over (order by id)
from ta

2000只有用临时表/新增显示列实现
create table ta(id int,name int)
insert ta select 1,2
union all select 1,3

select *,自编号=1 into # from ta
declare @i int
set @i=0
update # set 自编号=@i,@i=@i+1
查询:
select * from #
[解决办法]
--如果只是course做比較的話

declare @ta table(id char(3), course Nvarchar(10), 成绩 int)
insert @ta select '001 ', N '英语 ', 80
union all select '001 ', N '英语 ', 65
union all select '001 ', N '英语 ', 90

select * from @ta A Where 成绩 Not In (Select Max(成绩) From @ta Where course = A.course)

--Result
/*
idcourse成绩
001英语80
001英语65
*/


[解决办法]
--不用临时表

select *
from 表名 a
where 成绩 not in (select max(成绩) from 表名 where course = a.course and id = a.id)

热点排行