Jump to content


This topic is now archived and is closed to further replies.


SELECT with COUNTS and HAVINGS problems!

Recommended Posts

Hi All!

Here is some initial info:

Table reports_interventions has:

- id
- date
- player_id
- qu_id
- value

[b]What I'm trying to do is:[/b]

Select all the player_id's who have the the same qu_id three times or more.

[i]For example[/i]

date = 2006-05-20
player_id = 5
qu_id = 3
value = 4

date = 2006-05-21
player_id = 5
qu_id = 3
value = 3

date = 2006-05-22
player_id = 5
qu_id = 3
value = 7

[b]What I have currently is:[/b]

SELECT COUNT( qu_id ) , player_id
FROM reports_interventions
GROUP BY player_id, qu_id
HAVING COUNT( qu_id ) >3

The problem is that it selects all qu_ids and counts them.
What I want it to do is [b]select all qu_ids[/b] which are [b]the same[/b] which [b]occur 3 times or more[/b] for a [b]certain player_id.[/b]

Please Help!!!
Thanks to All!

Share this post

Link to post
Share on other sites
I'm not sure I understand why you have the second group clause.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.