Pretty new to SQL, so I apologize if this is obvious.
I have a table of the number of games sold and their corresponding rank in the bestseller list (1, 2, 3, etc.). This table is called ranking(rank: bigint, global_sales: double).
What I want to do is make a stored procedure that I can call whenever the sales update, and then this procedure can be called to update the rankings. Here's what I have so far, and I'm afraid it's probably very incorrect:
delimiter $$
drop procedure if exists updateRank;
create procedure updateRank()
begin
select *
from ranking
order by global_sales desc;
declare r bigint default 1;
loop1: loop
GameRank = r;
set r=r+1;
end loop loop1;
end $$
delimiter ;
From what I could find here and on Google, I couldn't find anything similar, although this is probably a fairly-common query. Any insight would be greatly appreciated.
Edit: I'm using MySQL Workbench version 8.0 CE