Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count intressting 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
Hi,

Table to hold soccer scores:
ID, ScoreTypeID, UserID, SeasonID

Since there are 3 Type of Scores (ScoreTypeID -> Goal (regular), Goal (penalty), Assist) it makes it a bit hard for me find out in ONE SINGLE QUERY how many Goals, Penalties and Assists a Players (UserID) scored within a Season (SeasonID).

I'd love to see results like this:
=======================================
userid, season, goal, penaly, assist
47, 03/04, 7, 1, 11
47, 04/05, 4, 2, 8
47, 05/06, 1, 0, 2

hmmm... this must be doable.

thanks
 
Something like this ?
SELECT UserID, SeasonID
, SUM(CASE WHEN ScoreTypeID='Goal (regular)' THEN 1 ELSE 0 END) Goal
, SUM(CASE WHEN ScoreTypeID='Goal (penalty)' THEN 1 ELSE 0 END) Penalty
, SUM(CASE WHEN ScoreTypeID='Assist' THEN 1 ELSE 0 END) Assist
FROM yourTable
GROUP BY UserID, SeasonID

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Okay, thats fancy and neat! worthwhile a star!
 
hi again,
further down the road I was thinking of a more dynamic way of querying by ScoreTypeID, since it's easily possible to that there are more ScoreTypes added to the System (e.g. 2nd Assist as in Streethockey.) Case-statement doesn't help in this case.

do you have any clue making it more dynamic? I wasn't able to TSQL commands/operators to do so. That I'd appreciate, as well.

Thanks heaps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top