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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating Winning and Losing Streaks?

Status
Not open for further replies.

spperl

Programmer
Mar 29, 2005
34
GB
Hi,

I have a table called 'results' which is made up of the following fields

Code:
id
team_id
result (Win, Loss, Draw)

I'm trying to construct a query that will show what streak a particular team is on. e.g.

Team 1 has won the last 5
Team 1 has drawn the last 0
Team 1 has lost the last 0

Team 2 has won the last 0
Team 2 has drawn the last 2
Team 2 has lost the last 0

Does anyone have any ideas on how to achieve this with a single query on MySQL? (it can be assumed that the results are ordered by id)

Any help or pointers would be greatly appreciated.

Many thanks.



 
If you want that answer from that database server and not from code, I think your best option is to write stored procedures or functions.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top