开发者

Select one record for conditions

开发者 https://www.devze.com 2022-12-19 21:58 出处:网络
I have a \"games\" table which contains player_id and player_action. player_id | player_action 1| move 1| m开发者_如何学Pythonove

I have a "games" table which contains player_id and player_action.

player_id | player_action  
1         | move  
1         | m开发者_如何学Pythonove  
1         | attack  
2         | attack  
2         | attack  
3         | move  
3         | move 

And I have to get all player with "move" action but only one row per player, result should looks like

1  |  move  
3  |  move

Would anyone have an idea on how to achieve this?


It looks like you intend to do the following:

SELECT
    player_id, player_action
FROM
    games
WHERE
    player_action = 'move'
GROUP BY
    player_id


select distinct player_id, player_action from games where player_action = "move"


Use the DISTINCT clause:

SELECT DISTINCT player_id, player_action FROM games WHERE player_action = 'move';

The distinct clause will remove duplicate records. (I'm sure there are many other solutions to this.)

0

精彩评论

暂无评论...
验证码 换一张
取 消