Search code examples
sqlsql-servert-sqlrow-numberanalytic-functions

Interesting Row_Number() bug


I was playing with the Stack Exchange Data Explorer and ran this query:
https://data.stackexchange.com/stackoverflow/query/2820/rising-stars-top-50-users-ordered-on-rep-per-day

Notice down in the results, rows 11 and 12 have the same value and so are mis-numbered, even though the row_number() function takes the same order by parameter as the query.

I know the correct fix here is to specify an additional tie-breaker column in the order by clauses, but I'm more curious as to why/how the row_number() function returned different results on the same data?

If it makes a difference anywhere, this runs on Azure.


Solution

  • The problem seems to be with significant digits. Eg: polygenelubricants has 22281 of reputation gained in 101 days, and KennyTM has 39257 of reputation gained in 178 days. The integer part of both RepPerDays is 220, but the floating value of Reputation/Days for polygenelubricants is 220.603#### and for KennyTM is 220.544####.

    You should try to order by Reputation / Days both times.