我如何 select 在过去 2 小时内或根本没有更新分数的用户使用 Mysql

How do I select users that have not had their score updated within the last 2 hours or at all using Mysql

我有以下 2 tables...

用户

user_id, name, age

user_score

score_id, user_id, score, date(timestamp)

user_score table 应该每 2 小时更新一次所有用户的所有分数日志。

因此我需要获取在过去 2 小时内或根本没有更新分数的所有用户 ID 的列表(对于新玩家)。我猜我将不得不使用 INNER JOIN?

如有任何帮助,我们将不胜感激。

您想要 left joinnot exists。您只需要过去两个小时内没有 activity 的所有记录(这也包括新用户):

select u.*
from users u
where not exists (select 1 from user_score us
                  where u.user_id = us.user_id and
                        us.date >= date_sub(now(), interval 2 hour)
                 );