ORDER BY t0.winGame DESC,t0.drawGame DESC, t0.allGame DESC, t0.userId DESC.
userId
, но тогда одинаковые позиции будут скакать вверх-вниз.SELECT
tables1.userId as userId,
tables1.winGame as winGame,
tables1.drawGame as drawGame,
tables1.loseGame as loseGame,
tables1.startGame as startGame,
tables1.allGame as allGame,
tables1.online as online,
tables1.onlineActive as onlineActive,
tables1.countNewWinGame as countNewWinGame,
tables1.countNewDrawGame as countNewDrawGame,
tables1.countNewAllGame as countNewAllGame,
tables1.rate as rate,
tables1.rate1 as rate1,
tables1.rate2 as rate2,
tables1.username as username,
tables1.isGuest as isGuest,
tables1.sumTimeGame as sumTimeGame,
t2.appearanceTS as dateRegister
FROM
(
SELECT
tables.userId as userId,
tables.winGame as winGame,
tables.drawGame as drawGame,
tables.loseGame as loseGame,
tables.startGame as startGame,
tables.allGame as allGame,
tables.online as online,
tables.onlineActive as onlineActive,
tables.countNewWinGame as countNewWinGame,
tables.countNewDrawGame as countNewDrawGame,
tables.countNewAllGame as countNewAllGame,
tables.sumTimeGame as sumTimeGame,
t1.username as username,
t1.isGuest as isGuest,
IF(t1.isGuest=1,@c:=@c+1,0) as rate1,
IF(t1.isGuest=0,@d:=@d+1,0) as rate2,
@b:=@b+1 as rate
FROM
(
SELECT
t0.userId as userId,
t0.winGame as winGame,
t0.drawGame as drawGame,
t0.loseGame as loseGame,
t0.startGame as startGame,
t0.allGame as allGame,
t0.countNewWinGame as countNewWinGame,
t0.countNewDrawGame as countNewDrawGame,
t0.countNewAllGame as countNewAllGame,
t0.sumTimeGame as sumTimeGame,
IF(UNIX_TIMESTAMP()-MAX(v3.lastBeacon)<=120,1,0) as online,
IF(UNIX_TIMESTAMP()-MAX(v3.lastActivity)<=300,1,0) as onlineActive
FROM
(
(
SELECT
temp.userId as userId,
SUM(CASE WHEN temp.resultGame IS NOT NULL THEN 1 ELSE 0 END) as allGame,
SUM(CASE WHEN temp.resultGame = 3 THEN 1 ELSE 0 END) as winGame,
SUM(CASE
WHEN (temp.resultGame = 2 OR
temp.resultGame = 4 OR
temp.resultGame = 5 OR
temp.resultGame = 6)
THEN 1 ELSE 0 END) as drawGame,
SUM(CASE WHEN temp.resultGame = 1 THEN 1 ELSE 0 END) as loseGame,
SUM(CASE WHEN temp.resultGame = 0 THEN 1 ELSE 0 END) as startGame,
SUM(CASE WHEN temp.resultGame=3 AND
UNIX_TIMESTAMP(temp.timeStart)>=UNIX_TIMESTAMP(CURDATE())
THEN 1 ELSE 0 END) as countNewWinGame,
SUM(CASE WHEN (temp.resultGame = 2 OR temp.resultGame = 4 OR
temp.resultGame = 5 OR temp.resultGame = 6) AND
UNIX_TIMESTAMP(temp.timeStart)>=UNIX_TIMESTAMP(CURDATE())
THEN 1 ELSE 0 END) as countNewDrawGame,
SUM(CASE WHEN UNIX_TIMESTAMP(temp.timeStart)>=UNIX_TIMESTAMP(CURDATE())
AND temp.numberMove>3
THEN 1 ELSE 0 END) as countNewAllGame,
SUM(temp.timeUser+temp.timeUI) as sumTimeGame
FROM `chess_historyui` temp
WHERE ".$where."
GROUP BY temp.userId
) as t0,
(SELECT @b:=0) AS `RowNumberTable`
)
LEFT JOIN
`user_activity` v3
ON (v3.gameVariationId=3 AND v3.userId=t0.userId)
GROUP BY t0.userId
ORDER BY t0.winGame DESC,t0.drawGame DESC, t0.allGame DESC, t0.userId DESC
) as tables
INNER JOIN
`kosynka_users` t1
ON (tables.userId=t1.userId AND tables.allGame>1),
(SELECT @c:=0) AS `RowNumberTable1`,
(SELECT @d:=0) AS `RowNumberTable2`
) tables1
LEFT JOIN
`user_games` t2
ON (t2.userId=tables1.userId AND t2.gameVariationId=3)
WHERE (".$where2.")".$order;
$where
— условие выборки по времени из php$where2
— условие выборки по статусу активности пользователя (онлайн, не онлайн) и по статусу гость/зарегистрированный$where2 = 'tables1.isGuest=1';
$where = '1=1';
$where=$where.' AND YEAR(temp.timeStart)=2013';
$order
— условие сортировки, например:$order = 'ORDER BY ';
$order = $order.'tables1.winGame '.$vs.', tables1.drawGame '.$vs.', tables1.allGame '.$vs.', tables1.userId '.$vs.'';
$vs = 'ASC'
или 'DESC'
Но тогда feature-ветка перед мержем должна быть "отребейзена" от мастера.
Тогда не будет merge-commit'а