I'm doing what I thought was a simple GROUP BY summary of fairly simple
data and the my numbers aren't working out
Some results are showing up <NULL> when I know the data is in the
database
I'm no SQL expert, but if I'm summing (SUM) multiple fields and adding
them together in my SELECT how does SUM handle Null? In some situations a
single column in a single row is Null but and it's part of a larger GROUP BY
and SUM and from looking it over I have a guess it's a problem with SUM
handling Null
I'm not sure the SQL will help you without the schema but here it is
anyways
thanks
mike
PS The schema can be found here...but I don't think you'll need it. So what
if in one row that is being grouped Batting.IBB is null?
SELECT Master.playerID , Master.nameFirs t, Master.nameLast ,
Batting.teamID, SUM(Batting.AB) + SUM(Batting.BB) + SUM(Batting.IBB ) +
SUM(Batting.HBP )
+ SUM(Batting.SH) + SUM(Batting.SF) AS PA
FROM Master INNER JOIN
Batting ON Master.playerID = Batting.playerI D
GROUP BY Master.playerID , Master.nameFirs t, Master.nameLast , Batting.teamID
HAVING (Batting.teamID = N'CIN' OR
Batting.teamID = N'CN2')
data and the my numbers aren't working out
Some results are showing up <NULL> when I know the data is in the
database
I'm no SQL expert, but if I'm summing (SUM) multiple fields and adding
them together in my SELECT how does SUM handle Null? In some situations a
single column in a single row is Null but and it's part of a larger GROUP BY
and SUM and from looking it over I have a guess it's a problem with SUM
handling Null
I'm not sure the SQL will help you without the schema but here it is
anyways
thanks
mike
PS The schema can be found here...but I don't think you'll need it. So what
if in one row that is being grouped Batting.IBB is null?
SELECT Master.playerID , Master.nameFirs t, Master.nameLast ,
Batting.teamID, SUM(Batting.AB) + SUM(Batting.BB) + SUM(Batting.IBB ) +
SUM(Batting.HBP )
+ SUM(Batting.SH) + SUM(Batting.SF) AS PA
FROM Master INNER JOIN
Batting ON Master.playerID = Batting.playerI D
GROUP BY Master.playerID , Master.nameFirs t, Master.nameLast , Batting.teamID
HAVING (Batting.teamID = N'CIN' OR
Batting.teamID = N'CN2')
Comment