View Single Post
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 08-21-2021 , 15:40   Re: SQL - Updating ID's efficiently
Reply With Quote #2

Can you elaborate on what exactly this is for, and what your final goal will be?

Quote:
Originally Posted by xice1337 View Post
The table is ordered by time so the most recent time should get number 1.
This one sounds like you want it dynamically, - similar to a ranking system?


If I'm the newest (highest number) right now, according to the Unix timestamp / EPOCH field "time", then I should be #1?

If then you're the newest in five minutes, then you need to be first, and I need to be #2 ( ... or even a later number )?


Quote:
Originally Posted by xice1337 View Post
Is there a good way to do this? I dont really wanna loop over every row to achieve this.
If you really insist on getting you database updated accordingly, in the "dynamic" style as explained above, you will need to "loop over every row" every time it needs an update.


However, if you're solely looking for the current rank (position) of the actual result, at the time of a SELECT query, you can use e.g.:

Code:
SET @position=0; SELECT (@position:=@position+1) AS _position, time FROM mytable ORDER BY time DESC;
to accomplish what you want.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline