gpt4 book ai didi

MySQL 加入 + "WHERE something=MAX(something)"

转载 作者:行者123 更新时间:2023-11-29 03:08:57 25 4
gpt4 key购买 nike

我有几个表需要连接。这些表是:

玩家

  • 名字
  • 姓氏
  • 性别
  • location_id
  • (其他不相关的列)

score_entries

  • 得分
  • 日期时间
  • 玩家编号
  • (其他不相关的列)

我需要根据 player_id 加入他们,并且只想选择 players.location_id 最大的记录。所以像这样:

SELECT
players.first_name,
players.last_name,
players.gender,
score_entries.score,
score_entries.datetime as jump_date
players.location_id,
FROM score_entries
LEFT JOIN players
ON score_entries.player_id = players.id
WHERE gender="m"
AND location_id="***(ONLY THE HIGHEST LOCATION_ID VALUE IN THE TABLE)***"

最佳答案

请尝试以下查询

SELECT 
players.first_name,
players.last_name,
players.gender,
score_entries.score,
score_entries.datetime as jump_date,
players.location_id
FROM score_entries
LEFT JOIN players
ON score_entries.player_id = players.id
WHERE gender="m"
AND players.location_id = (SELECT MAX(location_id) from players)

关于MySQL 加入 + "WHERE something=MAX(something)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11166631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com