Jump to content

Recommended Posts

Hey all,

 

I'm trying to figure out a score/ranking procedure from a SQL DB.  I am using MS Visual Studio.

I have the following tables[Attributes]:

Team[Name, Color]

Week[week_id, Date]

Game[week_id, home_team_name, away_team_name, home_team_score, away_team_score, reffing_team_name]

I want to run a stored procedure that will show all the teams, their wins/losses/ties, points, and ordered by rank which is based on points.  Points are calculated by wins +2, ties +1, losses +0.  The "Game" table only has scores from week_id 1-3.  Below is what I have so far, but it returns the same numbers for wins, ties, and losses.  And I haven't even started to figure out the ranking and points part yet, cause I can't even get the correct totals for W/T/L.  Any help would be greatly appreciated. 

AND FYI, I'm a noob to all this.

ALTER PROCEDURE dbo.GenerateStandingsReport
AS
BEGIN
SET NOCOUNT ON
SELECT 	reffing_team_name "Team", 
COUNT(CASE 
WHEN (home_team_name = reffing_team_name AND home_team_score > away_team_score) 
OR (away_team_name = reffing_team_name AND away_team_score > home_team_score) 
THEN 1 
ELSE 0
END) "Wins", /*--calculate team’s wins*/
COUNT(CASE
WHEN (home_team_name = reffing_team_name AND home_team_score = away_team_score) 
OR (away_team_name = reffing_team_name AND away_team_score = home_team_score) 
THEN 1	
ELSE 0 	
END) "Ties", /*--calculate team’s ties*/
COUNT(CASE 
WHEN (home_team_name = reffing_team_name AND home_team_score < away_team_score) 
OR (away_team_name = reffing_team_name AND away_team_score < home_team_score) 
THEN 1 
ELSE 0 
END) "Losses" /*--calculate team’s losses*/
FROM game, week
WHERE game.week_id = week.week_id
AND week.date < current_timestamp
GROUP BY reffing_team_name
ORDER BY wins DESC, ties DESC, losses ASC
END

 

Link to comment
https://forums.phpfreaks.com/topic/199861-stored-procedure-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.