search

Home  >  Q&A  >  body text

Get number of players from mysql

I need to get the number of users with rank =player

So far I have tried select count(*) as count_players from users whererank = player

I'm not sure where the error is, if it's only correct in tags and queries, or I'm completely wrong, thanks in advance for any suggestions!

Table:[User]

id username password Ranking
1 John $2y$10$zYharAUmf36hVzkYUg87y.avY Player
2 simple $2y$10$zYhajiIUGU89887jhgUg87yKJ8G administrator

COUNT_PLAYERS = 1

P粉037215587P粉037215587383 days ago433

reply all(1)I'll reply

  • P粉306523969

    P粉3065239692024-02-04 11:49:51

    Cully below is right, when you are going after a single result, you don't need to group it. When you group by rank, you do the following (and you don't do "rank='player'").

    SELECT COUNT(*) AS count_players FROM users WHERErank='player';

    Or if you want to group, choose COUNT(*) AS count_players FROM users GROUP BY ranking.

    Have you tried quoting your target ranking? It's a string, not a variable.

    reply
    0
  • Cancelreply