We help IT Professionals succeed at work.
Get Started

Count number of users with more than X played games

Kenni Larsen
Kenni Larsen asked
on
391 Views
Last Modified: 2021-04-21
Hi Experts

The following SQL query returns a list of users (alias/username) who have played more than 4,000 games in our game. Instead, I would like to know how many users it is in total.

SELECT players.alias AS "4000"
FROM players, games WHERE games.opponent_id = players.id OR games.player_id = players.id AND players.id NOT IN (SELECT bots.profile_id FROM bots)
GROUP BY players.id
HAVING COUNT(games.id) >= 4000

Open in new window


If I change the query so that it makes a count, I get the number of games that each user has played instead of the number of users who have played over 4,000 games.

SELECT COUNT(players.id) AS "4000"
FROM players, games WHERE games.opponent_id = players.id OR games.player_id = players.id AND players.id NOT IN (SELECT bots.profile_id FROM bots)
GROUP BY players.id
HAVING COUNT(games.id) >= 4000

Open in new window


Can you please help me write the correct query?
Thanks in advance!
Comment
Watch Question
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE