Jump to content


Photo

SELECT with COUNTS and HAVINGS problems!


  • Please log in to reply
1 reply to this topic

#1 schone

schone
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 May 2006 - 04:45 AM

Hi All!

Here is some initial info:

Table reports_interventions has:

- id
- date
- player_id
- qu_id
- value

What I'm trying to do is:

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

For example

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

What I have currently is:

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 select all qu_ids which are the same which occur 3 times or more for a certain player_id.

Please Help!!!
Thanks to All!
:)

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 May 2006 - 05:21 AM

I'm not sure I understand why you have the second group clause.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users