December 10th, 2012, 07:02 PM
Join Date: Dec 2012
Time spent in forums: 36 m 25 sec
Reputation Power: 0
Help on finding groups with a similar count as one groupmember on a certain column
I have two tables:
1: A table Person (P) which contains (among others) the column
2: A table Ticket (T) which contains (among others) the columns number and penalty.
I need to make a query to find all persons with the same amount of tickets as a certain person. In other words, if the person with number x has y penalties, I need to find all other persons with y penalties.
I already formulated the query beneath:
SELECT P.number, COUNT(T.penalty) number_of_tickets
FROM Person D, Ticket T
WHERE T.number = P.number
GROUP BY P.number
I guess I need to use 'HAVING' but am not sure how to solve my query.
Anyone can help a newbie?