complex mysql rank !
Posted
by silversky
on Stack Overflow
See other posts from Stack Overflow
or by silversky
Published on 2010-04-21T01:31:56Z
Indexed on
2010/04/21
1:33 UTC
Read the original article
Hit count: 468
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.
© Stack Overflow or respective owner