导航

SQL2005 with tie

Posted on 2010-03-30 08:47  杨彬Allen  阅读(189)  评论(0)    收藏  举报

網上很多版本都是錯的.

代码
create table #tb1([Name] nvarchar(20),score int)
insert into #tb1
select 'studentA',90 union all
select 'studentB',90 union all
select 'studentC',90 union all
select 'studentD',85 union all
select 'studentE',80 union all
select 'studentF',80 union all
select 'studentG',80 union all
select 'studentH',75 union all
select 'studentI',70 union all
select 'teacherA',90 union all
select 'teacherB',85
go
select * from #tb1 where [Name] like 'student%'
go
select top 5 * from #tb1 where [Name] like 'student%' order by score desc
go
select top 5 with ties * from #tb1 where [Name] like 'student%' order by score desc