Sql rank based on money system.

Hey guys, I want to make a rank system based on my money system (SQLite).

How would I go about making the highest amount of money goto the top and lowest goto the bottom? I’m open to a different way of doing this that way just made the most sense to me.

I have made functions for the money system The file looks like this:
[lua]
function ms:Money_Set( money )

self:SetNWInt( "money", tonumber(money) )

end

function ms:Money_Has( money )

local current = tonumber(self:GetNWInt( "money" ))

if current >= tonumber(money) then

	return true

else

	return false

end

end

function ms:Money_Add( money )

if money > 0 then

	local current = tonumber(self:GetNWInt( "money" ))

	self:Money_Set( current + money )

end

end

function ms:Money_Get()

local current = tonumber(self:GetNWInt( "money" ))

return current

end

function ms:Money_Take( money )

if self:Money_Has( money ) then

	local current = tonumber(self:GetNWInt( "money" ))

	self:Money_Set( current - money )

end

end
[/lua]

I used NWInt because my save function saves the money to the table with it, wasn’t sure if this was wrong I was going out on a limb using my lua knowledge doing this. I just wanted to tell you in case it was a bad or stupid thing todo…

you may take a look to the “ORDER BY” sql functions : http://www.sql-tutorial.com/sql-order-by-sql-tutorial/

I have no idea how the syntax works in SQLlite, but I did something similar with normal sql.

[lua]“SELECT money, (SELECT COUNT(*) FROM sometable members2 WHERE members2.money > members.money) AS rownumber FROM sometable members WHERE steamid=‘STEAM_ID:0:1:23456’ ORDER BY wins LIMIT 1”[/lua]

ok, I have been looking at the sql function for awhile, and I came up with this code to select players from my table “player_money” and order by the amount of “money”
[lua]
sql.Query( “SELECT * FROM player_money ORDER BY money” )
[/lua]
Would this be correct?

Yes, it should be. But use the DESC keyword to invert the sort order (ascending order by default):

[lua]
sql.Query( “SELECT * FROM player_money ORDER BY money DESC” )
[/lua]

oh yeah, I didn’t know what order they were in, Thanks.