MySQL UPDATE排名查询在本地工作,而不是在服务器上

时间:2017-12-14 16:51:43

标签: mysql sql-update ranking

我有一个带表格的体育池数据库:

  • pool(id,name,sport,type,season,startRound,endRound)
  • 条目(poolId,userId,entryId,poolPoints,poolRank)
  • picks(poolId,userId,entryId,round,pick,pickResult,pickPoints)

我可以通过pool / user / entry查询pickPoints并将其汇总到poolPoints中。然后我使用下面显示的查询根据poolPoints从最高到最低更新poolRank。我95%确定它以前在本地和我的服务器上都有效。现在它无法在服务器上运行,我无法弄清楚原因。

查询:

-- get current round and set as variable
SELECT round FROM hockey_games WHERE gameDate <= CURDATE() 
ORDER BY gameDate DESC LIMIT 1 INTO @round;

-- rank pick'em players (overall)
UPDATE mop_survivor_entries b 
INNER JOIN (
  SELECT poolId, userId, entryId, poolPoints, rank FROM (
    SELECT poolId, userId, entryId, poolPoints, 
    @curRank := IF(@prevPool != poolId, 1, IF(@prevRank = poolPoints, @curRank, @incRank)) AS rank,
    @incRank := IF(@prevPool != poolId, 2, @incRank + 1), 
    @prevRank := poolPoints,
    @prevPool := poolId
    FROM mop_pools c, mop_survivor_entries e, 
    (SELECT @curRank :=0, @prevRank := NULL, @prevPool := 604, @incRank := 1) r
    WHERE c.id = e.poolId
    AND sport = 'hockey'
    AND type = 'pickem'
    AND season = 2017
    AND startRound <= @round
    AND endRound >= @round
    ORDER BY poolId ASC, poolPoints DESC
    ) s
  ) a ON b.poolId = a.poolId AND b.userId = a.userId AND b.entryId = a.entryId 
SET poolRank = rank;

我认为这可能与我的用户定义的变量重置有关,但研究并没有对答案产生太多影响。

我尝试通过PHP运行查询,并使用phpMyAdmin运行相同(无更改)的结果。

MySQL版本略有不同。本地5.6.3;服务器5.5.58 ......但是再次感觉它以前工作了。感谢有人给予的任何帮助。

0 个答案:

没有答案