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

SQL语句有关问题,详情请进

2012-02-10 
SQL语句问题,详情请进LeiXingvaluexingming100190学生1100130学生2100180学生3100152学生4100250学生51002

SQL语句问题,详情请进
LeiXing     value     xingming
1001             90           学生1
1001             30           学生2
1001             80           学生3
1001             52           学生4
1002             50           学生5
1002             62           学生6
1002             60           学生7
1002             30           学生8
1002             50           学生9

用语句得到LeiXing   相同的前三位的xingming   和value  
1001             90           学生1
1001             80           学生3
1001             52           学生4
1002             62           学生6
1002             60           学生7
1002             50           学生5
1002             50           学生9
 


[解决办法]
create table test(LeiXing int,value int,xingming varchar(20))
insert test select 1001,90, '学生1 '
union all select 1001,30, '学生2 '
union all select 1001,80, '学生3 '
union all select 1001,52, '学生4 '
union all select 1002,50, '学生5 '
union all select 1002,62, '学生6 '
union all select 1002,60, '学生7 '
union all select 1002,30, '学生8 '
union all select 1002,50, '学生9 '


select * from test a where value in
(
select top 3 value from test where LeiXing=a.LeiXing order by value desc
)

热点排行