Jump to content

Calculating streak in table


karimali831

Recommended Posts

Hi,

 

This query will show match stats of a user, the query is the output in the attatchment.

I want to calculate the streak if score1 is greater than score2. So basically, in the attatchment I have selected 3 rows, these 3 rows should be a 3 streak because the user won 3 matches in a row (according to date)

 

SELECT * FROM webs_cup_matches WHERE ladID='17' AND (clan1 != '0' AND clan2 != '0') AND (clan1='2630' || clan2='2630') AND (clan1 != '2147483647' AND clan2 != '2147483647') ORDER BY date DESC

 

any help appreciated.

 

[attachment deleted by admin]

Link to comment
Share on other sites

That's best done in php, I wouldn't try to express it in SQL.  You can loop through the results from MySQL remembering the following values:

 

1.  How long the current streak is

2.  How long the longest streak was

 

Remember to check at the end (after the loop has finished) to see if the last streak is the longest.

Link to comment
Share on other sites

Would you be able to help me out on this please? I'm not familar how to do this with PHP.

If you take a look at the attatchment in my first post, I've explained why the streak should be 3.

 

But not sure how to build this expression.

I'm working on a ladder system project and I'm stuck on this bit (http://team-x1.co.uk/site/index.php?site=standings&ladderID=17) so any help at all, I'll be grateful.

Link to comment
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.