Jump to content

SELECT with COUNTS and HAVINGS problems!


schone

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]

[code]
SELECT COUNT( qu_id ) , player_id
FROM reports_interventions
GROUP BY player_id, qu_id
HAVING COUNT( qu_id ) >3
[/code]

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!
:)
Link to comment
https://forums.phpfreaks.com/topic/10236-select-with-counts-and-havings-problems/
Share on other sites

Archived

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

×
×
  • Create New...

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.