0

我有一个系统可以查询不同坐标的游戏活动数据库表。我需要查询某个玩家的活动,但我需要排除在相同坐标处匹配新条目的任何活动(是否由其他玩家,只是任何东西)。

示例查询是:

SELECT * FROM prism_actions
WHERE world = 'world'
AND (action_type = 'block-place')
AND (player = 'viveleroi')
AND (x BETWEEN -448.7667627678472 AND -438.7667627678472)
AND (y BETWEEN 62.0 AND 72.0)
AND (z BETWEEN -291.17236958025796 AND -281.17236958025796)
ORDER BY x,y,z ASC
LIMIT 0,1000000

我试过让它与子查询和内部连接一起工作,但就是无法得到它。我也真的需要能够快速完成这项工作。

本质上,当有另一条具有相同 X、Y、Z 但具有新 action_time 的记录时,我需要此查询来排除坐标 X、Y、Z 处的任何记录。

当输入新匹配时,我还考虑过某种方式在相同的 x、y、z 处过期记录,但这似乎也没有我想要的那么有效。

4

1 回答 1

0

您可以通过加入过滤掉“最新”坐标的子查询来做到这一点:

SELECT prism_actions.*
FROM prism_actions
JOIN (
    SELECT x, y, z, max(action_time) as action_time
    FROM prism_actions
    GROUP BY x, y, z) latest
  ON prism_actions.action_time = latest.action_time
  AND prism_actions.x = latest.x
  AND prism_actions.y = latest.y
  AND prism_actions.z = latest.z
WHERE prism_actions.world = 'world'
AND (prism_actions.action_type = 'block-place')
AND (prism_actions.player = 'viveleroi')
AND (prism_actions.x BETWEEN -448.7667627678472 AND -438.7667627678472)
AND (prism_actions.y BETWEEN 62.0 AND 72.0)
AND (prism_actions.z BETWEEN -291.17236958025796 AND -281.17236958025796)
ORDER BY x,y,z ASC
LIMIT 0,1000000
于 2013-01-01T21:44:39.007 回答