I have a table with these columns: win, los, id ...
I want to order the table by this index: win / ( win + los ) * 30 + win / SUM(win) * 70 and then to find the rank for two id's. I'm not very good on mysql, so what I wrote is totally wrong. (It uses Perl + DBI + DBD::mysql):
$stmt=$con->prepare("SET @rk := 0");
$stmt=$con->prepare("SELECT rank, id FROM (
SELECT @rk := @rk + 1 AS rank,
(win/(win+los)*30+win/SUM(win)*70) AS index,
win, los, id
FROM tb_name ORDER BY index DESC) as result
WHERE id=? AND id=?");
$stmt -> bind_param ("ii", $id1, $id2);
$stmt -> execute();
$stmt -> bind_result($rk, $idRk);
And also this query it suppose to run maybe every 5-10 sec for every user, so I'm trying to find something very, very fast. If it's necessary I could add, change, delete any column, in order to be as fast as possible.