This is strange... Changingselect a.theDatafrom ( select theData, num = (select count(*) from #sample t2 where t2.theData <= t.theData) from #sample t ) awhere ABS(num - (select count(*) from #sample where theData <= 'bumpers')) <= 1
to thisselect a.theDatafrom ( select theData, num = (select count(*) from #sample t2 where t2.theData <= t.theData) from #sample t ) awhere num - (select count(*) from #sample where theData <= 'bumpers') between -1 and 1
resulted in one extra table scan!
E 12°55'05.25"N 56°04'39.16"