create table #Stuscore
(
name nvarchar(20),
score int
)
insert into #Stuscore values ('陈一',100),('张二',100),('王五',90),('李四',80);
select top 1 with ties * from #Stuscore order by score desc
如果不加with ties 结果如果用并列的,只能查出一个,如上面的例子中,如果写成
select top 1 * from #Stuscore order by score desc,就只能查出张三这一条,但我们的本意是查出最高成成绩的学员,因此这时用with ties就体现出它的作用了。