January 6, 2005 at 6:28 pm
Hi all,
I need help with a query. I have a stats table with several hundred thousand rows of hockey stats. I have been asked to produce a list of everyone who played for all six "Original-Six" teams in the sixties. (I honestly don't know if such a person exists...but should know if someone helps me and I promise to share the answer)
The stats table has (among other columns) a player id and a team id. So I essentially need a query that selects distinct playr ids where teams are in 6 particular team ids. My limited T-SQL skill keep producing resultsets with the 2961 players who have played for ANY of the original 6 teams as opposed to only those who actually played for ALL six.
Any help appreciated.
JW
January 6, 2005 at 8:39 pm
I wasn't able to do it in one query -- maybe someone else will figure that out.
Here is an example involving 2 steps:
insert into stats select 1,2
insert into stats select 1,3
insert into stats select 1,4
insert into stats select 1,5
insert into stats select 1,6
insert into stats select 1,7
insert into stats select 1,8
insert into stats select 1,9
insert into stats select 2,1
insert into stats select 2,2
insert into stats select 2,3
insert into stats select 2,4
insert into stats select 2,1
insert into stats select 2,2
insert into stats select 2,3
insert into stats select 2,4
insert into stats select 3,1
insert into stats select 3,2
insert into stats select 3,3
insert into stats select 3,4
insert into stats select 3,5
insert into stats select 3,6
into #temp
from stats
where teamId in (1,2,3,4,5,6)
group by playerID, teamID
-----------
1
3
Aunt Kathi Data Platform MVP
Author of Expert T-SQL Window Functions
Simple-Talk Editor
January 7, 2005 at 6:56 am
from (select distinct playerID,teamId
where teamId in (1,2,3,4,5,6)) a
group by playerID
Far away is close at hand in the images of elsewhere.
Anon.
January 7, 2005 at 5:28 pm
Thanks very much...that did it. And the answer is that no player ever played for all Original 6 teams, but 6 played for 5 of the teams. Thanks
JW
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply