[thelist] Silly SQL
Jason Handby
jason_handby at illustraresearch.com
Thu May 27 09:24:08 CDT 2004
> Greetings, all. I've got a query that looks like this:
>
> select vUserVotedFor as user,
> sum(vCitizenship) as ciTotal,
> sum(vLeadership) as leTotal,
> sum(vAcademics) as acTotal,
> sum(vCharacter) as chTotal
> from tblVotes
> group by vUserVotedFor
>
> And that returns this:
>
> User ciTotal leTotal acTotal chTotal
> ----------- ------- ------- ------- -------
> Ablood 55 55 40 50
> Bruckman 63 65 59 62
> Tkrimminger 59 65 55 59
> Jhines 66 66 68 68
> Jmward 61 65 66 63
> Ccrouch 60 63 65 63
>
> What I'm looking for is a way to also return the total of all
> four numeric columns added together (ciTotal + leTotal +
> acTotal + chTotal = ???). I want to return the total score
> for each user. I tried nesting another query in there, but I
> can't quite get my brain around how this is supposed to work.
This might work:
select vUserVotedFor as user,
sum(vCitizenship) as ciTotal,
sum(vLeadership) as leTotal,
sum(vAcademics) as acTotal,
sum(vCharacter) as chTotal,
sum(vCitizenship + vLeadership + vAcademics + vCharacter) as
userTotal
from tblVotes
group by vUserVotedFor
Jason
More information about the thelist
mailing list