MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 23rd, 2003, 12:29 PM
el_geezer el_geezer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 2 el_geezer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to use SUM from MySQL on several occasions with the same column

Hi there,

I am trying to create a page that once I have entered football results into the database, it will dynamically produce the table showing games played, won, drawn, lost, goals for, goals against and goal difference. The two tables are:

*efl_teams
team_id
team_name

*efl_matches
efl_match_id
efl_match_home (team_id of home_team)
efl_match_home_score
efl_match_away (team_id of away team)
efl_match_away_score
efl_match_played (0 if match not played, 1 if match played)

I have managed to put together some code that will show in the descending order all the teams that have won matches. I cannot figure out how to use the same to list teams that have drawn or lost matches though:

mySQLwins="SELECT *, SUM(efl_match_played) as wins FROM efl_teams, efl_matches WHERE team_id = efl_match_home AND efl_match_home_score > efl_match_away_score OR team_id = efl_match_away AND efl_match_home_score < efl_match_away_score GROUP BY team_id ORDER BY wins DESC"

Any help would be great!

Reply With Quote
  #2  
Old February 1st, 2003, 02:52 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
el_geezer,

Are you trying to have all the SUMS in one single query, or are you trying to do this with multiple queries?

What server-side language are you using to integrate this?
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old February 3rd, 2003, 02:13 AM
el_geezer el_geezer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 2 el_geezer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

I'm using ASP and the aim is to use all the SUMs in one single query then loop through all the teams with the most points in descending order. I'd be interested to know if the loop could be done with multiple queries though.

tom

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > How to use SUM from MySQL on several occasions with the same column


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway