• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

AAC function to get the highest 5 storage value

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
201
I have this function
Code:
local query = db.getResult("SELECT `player_id`, `value` FROM `player_storage` WHERE `key` = 123781 and `value` >= 0 ORDER BY cast(value as SIGNED) DESC;")

this function will return the value of the largest 123781 storage of the players.
For example the largest storage 123781 is from the Jokyz player, and it has a value of 1000.
This function will return 1000.
How do I get the function to get the fifth highest value of the 123781 storage?

for exemple:
Jokz have storage 123781 value 1000
Jevia have storage 123781 value 988
Newk have storage 123781 value 355
Plok have storage 123781 value 200
Newbi have storage 123781 value 122

as the fifth largest storage is from Newbie, I need to get back to me the value of 122
 
I have this function
Code:
local query = db.getResult("SELECT `player_id`, `value` FROM `player_storage` WHERE `key` = 123781 and `value` >= 0 ORDER BY cast(value as SIGNED) DESC;")

this function will return the value of the largest 123781 storage of the players.
For example the largest storage 123781 is from the Jokyz player, and it has a value of 1000.
This function will return 1000.
How do I get the function to get the fifth highest value of the 123781 storage?

for exemple:
Jokz have storage 123781 value 1000
Jevia have storage 123781 value 988
Newk have storage 123781 value 355
Plok have storage 123781 value 200
Newbi have storage 123781 value 122

as the fifth largest storage is from Newbie, I need to get back to me the value of 122

You do this with OFFSET.
For your example, it would be LIMIT 1 OFFSET 4.
Why 4?
To get what you need, you should limit the search to get only one by one, then OFFSET will work like a "page".
If you want the 5th, you need LIMIT 1 OFFSET 4.
If you want the 3th, you need LIMIT 1 OFFSET 2.
If you want the nth, you need LIMIT 1 OFFSET n-1.

Now, for example, if you do this:
LIMIT 2 OFFSET 5
It will shows you the 6th and the 7th. In other words, it will shows 2 rows (LIMIT 2) after jump 5 rows (OFFSET 5).

Finally, it's like LIMIT rowsPerPage OFFSET = (page - 1) * rowsPerPage.
Your case:
rowsPerPage = 1
page = 5
Formula: LIMIT rowsPerPage OFFSET = (page - 1) * rowsPerPage
LIMIT 1 OFFSET (5 - 1) * 1
LIMIT 1 OFFSET 4
 
Back
Top