I have a tb with this col: ein, los, id ...
I whant 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 whath I wrote it's totally wrong:
$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 supouse to run maybe every 5-10 sec for every user, so I'm trying to find something very, very fast.
if it's necesary I could add, change, delete any column, in order to be as faster as posible.