Is it possible to count all rows with the same id with COUNT?

后端 未结 1 948
天命终不由人
天命终不由人 2021-01-06 02:17

PostgreSQL 9.4.

I have the following table:

   id             player_id
serial PK          integer
---------------------------
   1              


        
相关标签:
1条回答
  • 2021-01-06 03:00

    If all you need is a count of the number of rows where player_id is 1, then you can do this:

    SELECT count(*)
    FROM your_table_name
    WHERE player_id = 1;
    

    If you want to count the number of rows for each player_id, then you will need to use a GROUP BY:

    SELECT player_id, count(*)
    FROM your_table_name
    GROUP BY player_id;
    
    0 讨论(0)
提交回复
热议问题