How to get the counted values with a comma separator as a single row value

前端 未结 1 1320
执笔经年
执笔经年 2021-02-11 02:48

Using the following query I getting the result like how much the players in the table, but now I also want which players are in the same table, and show those players id with a

相关标签:
1条回答
  • 2021-02-11 03:16

    The function you are looking for is GROUP_CONCAT. See the documentation:

    http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat

    In your example you can just create one more subquery (example below). Or JOIN it in a standard way to the original query.

    ...
    (
          SELECT GROUP_CONCAT(gtp.id)
              FROM game_table_players gtp
              LEFT JOIN game_rounds gr ON gr.id = gtp.game_round_id
          WHERE gt.id = gtp.game_table_id
              AND gtp.quit<>1 AND gr.finish=0
    ) AS players,
    ...
    

    Note the comment on NULL handling in GROUP_CONCAT. If you want to show zeros when there aren't any players present, you might want to use COALESCE(GROUP_CONCAT(gtp.id), 0) instead.

    0 讨论(0)
提交回复
热议问题