all groups > sql server programming > september 2004 >
You're in the

sql server programming

group:

Need help on this Query


Need help on this Query anonymous NO[at]SPAM devdex.com
9/10/2004 9:21:31 PM
sql server programming:
I have two tables
tbl_participants
part_id PK
full_name

tbl_weekly_picks

part_id FK
pick_winner
actual_winner
total_pts

I want to do a sql query to find the total wins, losses and pts. The
pts are easy as they are a computed field (sum(total_pts)). If the
actual_winner = pick_winner then it is a win else it is a loss. Please
help




*** Sent via Developersdex http://www.developersdex.com ***
Re: Need help on this Query EricT
9/11/2004 12:10:06 AM
It's hard to tell what you're after exactly. But the
following may be helpful:

select
p.full_name,
sum ( case
when actual_winner = pick_winner then 1
else 0
end ) as total_wins,
sum ( case
when actual_winner <> pick_winner then 1
else 0
end ) as total_losses
from tbl_weekly_picks wp join tbl_participants p on
p.part_Id = wp.part_id
group by p.full_name

I'll be curious to know if this is helpful.

et

[quoted text, click to view]
AddThis Social Bookmark Button