【发布时间】:2015-11-11 16:30:59
【问题描述】:
我正在尝试运行一个查询,该查询返回特定用户组执行的最后一个“游戏”或操作。我不得不加入几张桌子才能最终得到我想要的东西,但这基本上现在返回了每个用户的游戏。我想参加他们的最后一场比赛。我在查询中将 max(___) 添加到时间戳,但它最终只返回了最近玩过的游戏,仅此而已。理想情况下,我希望看到每个用户及其最后的操作。
SELECT teamName, test_teams.userID, test_teams.timestamp AS signup, sponsorship, test_results.timestamp, stadium, win+draw+lose AS games
FROM test_teams
INNER JOIN test_profile
ON test_teams.userID = test_profile.userID
INNER JOIN test_results
ON test_teams.userID = test_results.homeTeamId
WHERE test_teams.timestamp >= '2015-11-04 00:00:00' and win+draw+lose > 100
ORDER BY games desc;
【问题讨论】:
-
你用的是什么关系型数据库?
标签: sql join max inner-join