Home » SQL & PL/SQL » SQL & PL/SQL » Count Records with value reference
Count Records with value reference [message #9547] Tue, 18 November 2003 23:57 Go to next message
eggohead
Messages: 3
Registered: October 2003
Junior Member
Hello I have the following query and output. In addition to the code below I need a where clause or condition to also count players that have >=2 "Kneee Injury" from player_injury.injury_type. I do not need to display this column but need to include its condition in the code below? - Any suggestions? - Thanks

break on school on player
SELECT DISTINCT SCHOOL.SCHOOL, PLAYER.PLAYER, PLAYER_INJURY.INJURY_TYPE
FROM SCHOOL, PLAYER, PLAYER_INJURY
WHERE PLAYER.PLAYER = PLAYER_INJURY.PLAYER
AND PLAYER.SCHOOL = SCHOOL.SCHOOL
AND player.player IN(select player.player from player, player_injury
where PLAYER.PLAYER = PLAYER_INJURY.PLAYER
group by player.player
having count(*) > 6)
order by school, player, injury_type;

SCHOOL PLAYER INJURY_TYPE
------------------------------ ------------------------------ ----------------------------------------
Penn State Univ. Johnson, P. Cracked Rib
Dislocated Shoulder
Twisted Ankle
Pondunk Univ. Trapp, M. Eye Injury
Knee Injury
Leg Injury
Thumb Injury
Re: Count Records with value reference [message #9550 is a reply to message #9547] Wed, 19 November 2003 01:40 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
How about this:
SELECT DISTINCT SCHOOL.SCHOOL
     , PLAYER.PLAYER
     , PLAYER_INJURY.INJURY_TYPE
  FROM SCHOOL, PLAYER
     , PLAYER_INJURY
 WHERE PLAYER.PLAYER = PLAYER_INJURY.PLAYER
   AND PLAYER.SCHOOL = SCHOOL.SCHOOL
   AND PLAYER.PLAYER IN( SELECT PI.PLAYER
                           FROM PLAYER_INJURY PI
                          WHERE PLAYER.PLAYER = PI.PLAYER
                            <B>AND PI.INJURY_TYPE = 'Knee Injury'</B>
                          GROUP BY PI.PLAYER
                         HAVING COUNT(*) > <B>2</B>)
 ORDER BY school, player, injury_type;
Re: Count Records with value reference [message #9556 is a reply to message #9550] Wed, 19 November 2003 07:53 Go to previous message
eggohead
Messages: 3
Registered: October 2003
Junior Member
Hello I still need to list players that have 6 injuries or more then have a condition where at least 2 of them are knee injuries? Currently the query below list each players injuires distinctivley >6 The 'Knee Condition' can not affect this only weed out those people from the below query that do not meet the conditin of > 2 'Knee Injuries'. Hope I made this clear, thanks for your help.

break on school on player
SELECT DISTINCT SCHOOL.SCHOOL, PLAYER.PLAYER, PLAYER_INJURY.INJURY_TYPE
FROM SCHOOL, PLAYER, PLAYER_INJURY
WHERE PLAYER.PLAYER = PLAYER_INJURY.PLAYER
AND PLAYER.SCHOOL = SCHOOL.SCHOOL
AND player.player IN(select player.player from player, player_injury
where PLAYER.PLAYER = PLAYER_INJURY.PLAYER
group by player.player
having count(*) > 2)
order by school, player, injury_type;
Previous Topic: what's the order of the return record from select
Next Topic: Using Long column in WHERE CLAUSE
Goto Forum:
  


Current Time: Wed May 08 06:01:59 CDT 2024