21C
05-16-2005, 04:19 AM
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: <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody><tr> <td class="alt2" style="border: 1px inset ;"> "SELECT TOP 20 Master.nameLast, Master.nameFirst, Batting.teamID, " & _
"SUM(Batting.G) AS G, MAX(Batting.yearID) AS LastYear " & _
"FROM Batting INNER JOIN Master ON Batting.playerID = Master.playerID " & _
"GROUP BY Master.nameLast, Master.nameFirst, Batting.teamID, " & _
"Batting.teamID, Batting.playerID " & _
"HAVING Batting.teamID='" & List2.Text & "' " & _
"ORDER BY SUM(Batting.G) DESC" </td> </tr> </tbody></table>
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: <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody><tr> <td class="alt2" style="border: 1px inset ;"> SELECT DISTINCT teamID FROM Teams WHERE franchID ='ANA' </td> </tr> </tbody></table>
I sort of have it working as I've used: <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody><tr> <td class="alt2" style="border: 1px inset ;"> "HAVING Batting.teamID IN (" & _
"SELECT DISTINCT teamID From Teams WHERE franchID='" & List2.Text & "') " & _
"ORDER BY SUM(Batting.HR) DESC" </td> </tr> </tbody></table>
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?
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: <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody><tr> <td class="alt2" style="border: 1px inset ;"> "SELECT TOP 20 Master.nameLast, Master.nameFirst, Batting.teamID, " & _
"SUM(Batting.G) AS G, MAX(Batting.yearID) AS LastYear " & _
"FROM Batting INNER JOIN Master ON Batting.playerID = Master.playerID " & _
"GROUP BY Master.nameLast, Master.nameFirst, Batting.teamID, " & _
"Batting.teamID, Batting.playerID " & _
"HAVING Batting.teamID='" & List2.Text & "' " & _
"ORDER BY SUM(Batting.G) DESC" </td> </tr> </tbody></table>
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: <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody><tr> <td class="alt2" style="border: 1px inset ;"> SELECT DISTINCT teamID FROM Teams WHERE franchID ='ANA' </td> </tr> </tbody></table>
I sort of have it working as I've used: <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody><tr> <td class="alt2" style="border: 1px inset ;"> "HAVING Batting.teamID IN (" & _
"SELECT DISTINCT teamID From Teams WHERE franchID='" & List2.Text & "') " & _
"ORDER BY SUM(Batting.HR) DESC" </td> </tr> </tbody></table>
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?