我有一个“游戏”表,其中包含player_id
和player_action
。
player_id | player_action
1 | move
1 | move
1 | attack
2 | attack
2 | attack
3 | move
3 | move
我必须让所有玩家都采取“移动”动作但每个玩家只有一行, 结果应该是
1 | move
3 | move
有人会知道如何实现这个目标吗?
答案 0 :(得分:2)
看起来您打算执行以下操作:
SELECT
player_id, player_action
FROM
games
WHERE
player_action = 'move'
GROUP BY
player_id
答案 1 :(得分:0)
select distinct player_id, player_action from games where player_action = "move"
答案 2 :(得分:0)
使用DISTINCT子句:
SELECT DISTINCT player_id, player_action FROM games WHERE player_action = 'move';
distinct子句将删除重复记录。 (我相信还有很多其他解决方案。)