with ties

 select top 8 *   from tablett order by state desc

 

select top 8 with ties *   from tablett order by state desc

 

区别就是用了with ties 最后一行的参数值(在这句里是state相同 ) 如果相同的话 会都显示出来

 

额外的返回行的参数值与TOP n(PERCENT)行中的最后一行的该参数值相同。这个地方该怎么理解呢?其实是如果按照order by 参数排序TOP n(PERCENT)返回了前面n(pencent)个记录,但是n+1…n+k条记录和排序后的第n条记录的参数值(order by 后面的参数)相同,则n+1、…、n+k也返回。n+1、…、n+k就是额外的返回值。

posted on 2018-04-23 16:34  heihaha  阅读(220)  评论(0编辑  收藏  举报