05-16-2005, 04:19 AM | #1 | |||||
College Prospect
Join Date: Jul 2001
Location: Newcastle, Australia
|
Programming Question - SQL Help Needed
I've been playing around with the Lahman baseball database ( Access 2000 ) in Visual Basic 6 and successfully queried it to get team records for home runs or hits but I'm just trying to improve it a little.
So far, I've found a team record by grouping everything by the Batting.teamID. The only problem is that this creates separate records for Anaheim, California and LA Angels, for example, while it should be one that encompasses all of these. There is a Teams.franchID that links these but this is where I get stuck. This is the query I used which gave separate results:
I wanted to adjust the Batting.teamID='" & List2.Text & "' part. Instead of matching a single Batting.teamID, I wanted to look for several. Some franchises have different Batting.teamID - like the Angels have ANA, CAL and LAA. I can find these using:
I sort of have it working as I've used:
but I just checked one and found Hank Aaron listed twice among the Braves leaders - once for Milwaukee and once for Atlanta. He should appear once with the totals combined. The only team/franchise ID in the Batting table is teamID. How do I group Aaron with Batting.teamID's of ML1 and ATL to be part of the franchise leaders of the Braves that have a Teams.franchID of ATL and Teams.teamID's of ATL, BSN and ML1? |
|||||
05-16-2005, 04:51 AM | #2 | |||
Pro Starter
Join Date: Dec 2003
Location: At the corner of Beat Street and Electric Avenue
|
Quote:
Okay, I don't know if I could help you all that much since I don't know what the purpose of franchID is, but couldn't you just get the totals by doing this.
Then just leave the rest of the code from the top example alone and try and see if this works. Hopefully my syntax isn't off. |
|||
05-16-2005, 08:03 AM | #3 | |
College Prospect
Join Date: Jul 2001
Location: Newcastle, Australia
|
Teams.franchID has the franchise info ( like ANA ) and Teams.teamID has the team info ( like ANA, CAL and LAA ).
yearID lgID teamID franchID 1993 AL CAL ANA 1999 AL ANA ANA Using this:
Gives me the different teamID's which I want to be able to use with teams like the Braves, Dodgers, Brewers and any other teams that moved cities ( or changed names or changed leagues ) but retained their franchise status. Your suggestion didn't quite work since the franchID's are all ANA - the teamID's are different. I'm thinking that the problem lies with the GROUP BY portion. It's grouping the stats by Batting.teamID. It is putting the correct franchise information together but not grouping by Teams.franchID. I may have to make some alterations with the JOIN. Thanks for taking a look. |
|
05-16-2005, 10:14 AM | #4 |
College Starter
Join Date: Feb 2004
Location: Buffalo, NY
|
You're selecting and grouping by the teamId, but an individual player may be joined to multiple teamIds.. so of course you're going to get mutliple listings. If your eally want everything selected and grouped by franchId, then use that instead. It looks like you'll need to add in another join to the team table to get the franchId.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|