I'm wondering what the query is to calculate reputation. I know how to select the individual components of reputation but it seems pretty difficult to put them all together in one query...

Are there any examples out there that show this?

1 Answer 1


I'm just taking a wild stab at this since I don't really know anything, but it would seem that calculating reputation is an algorithm that can't easily be expressed as a SELECT query.

It involves many conditions that not only work on rows but on spans of rows within the set of data corresponding to your activity. For example, identical rows have to be treated differently depending on whether their timestamp is before or after you hit the reputation cap on a date, which itself is defined by the same set of rows.

Of course it's possible to do in SQL, just like it's possible to write Microsoft Word by hand in machine code, but it may be a situation where it's not worth the time to write such a complex thing when it's more easily expressed in other ways.

https://stackoverflow.com/reputation gives you the breakdown without having to write a query if you just want to verify the components that went into your total.

  • @Dan, by other ways do you mean expressed as a denormalized field?
    – Mohamad
    Commented Feb 8, 2011 at 2:58
  • Yes, which is calculated either by a stored procedure, or a combination of C# and SQL. I expect it to be easier to calculate reputation using at least one loop rather than purely functional SQL. It's definitely not calculated on-the-fly as moderator actions routinely leave a user in a situation where their reputation is higher or lower than it would be if they click the 'recalc' button on the reputation page. Commented Feb 8, 2011 at 3:00
  • @Dan, that would imply a large number of queries, right? Using a loop, that is!
    – Mohamad
    Commented Feb 8, 2011 at 3:36
  • One query for your activity, then a loop over the results in which you calculate the reputation.That lets you keep track of whether you've reached the rep cap on each date as you move through the rows, and treat the rows after the cap differently than those before, until you reach the next day. Commented Feb 8, 2011 at 4:12
  • @Dan, thank you! This makes sense now. Although it seems interesting. I don;t think it's possible to dervice activity from the votes table. It would to be from the posts table which joins votes, no?
    – Mohamad
    Commented Feb 8, 2011 at 16:11
  • @Dan could you maybe merge your comments into your answer, as I think they'd complement it as a "well, if you do want to go the long way, here's a way to get started:"
    – Earlz
    Commented Feb 8, 2011 at 22:59
  • @Mel Don't forget that until 1000 reputation you now earn reputation for suggested edits which are accepted by two other users. Add that to (upvotes on questions, upvotes on answers, downvotes on questions, downvotes on answers, accepted answers, bounties awarded, bounties received) to keep track of. Commented Feb 9, 2011 at 1:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .