I’m building a page that displays various longest streaks from a table that contains data for one single team.
The data is presented in the following manner:
[table]
[tr]
[td]date[/td]
[td]result[/td]
[td]gf[/td]
[td]ga[/td]
[td]venue[/td]
[/tr]
[tr]
[td]1980-08-16[/td]
[td]W[/td]
[td]3[/td]
[td]0[/td]
[td]H[/td]
[/tr]
[tr]
[td]1980-08-19[/td]
[td]W[/td]
[td]3[/td]
[td]2[/td]
[td]A[/td]
[/tr]
[tr]
[td]1980-08-23[/td]
[td]W[/td]
[td]2[/td]
[td]1[/td]
[td]H[/td]
[/tr]
[tr]
[td]1980-08-25[/td]
[td]D[/td]
[td]0[/td]
[td]0[/td]
[td]A[/td]
[/tr]
[/table]
… and so on.
I am able to calculate overall streaks in the data for wins, defeats and undefeated etc, but I’m having trouble in further refining the query so that it returns streaks where a game is H or A. For example, the code I use to get the overall win streak is:
[php]SELECT result, type, MIN(date) as StartDate, MAX(date) as EndDate, COUNT() as Games
FROM (SELECT result, type, date, compfull, (SELECT COUNT()
FROM resultengine R
WHERE R.result <> RE.result
AND R.date <= RE.date) as RunGroup
FROM resultengine RE) A WHERE result=‘W’ GROUP BY result, RunGroup ORDER BY Games[/php]
I’ve tried various methods of introducing a subsequent where clause that refines results to those that are “h” for home games, such as this example:
[php]SELECT
result,
venue,
MIN(date) as StartDate,
MAX(date) as EndDate,
COUNT() as Games
FROM
(
SELECT
result,
venue,
date,
(
SELECT
COUNT()
FROM
resultengine R
WHERE
R.result <> RE.result
AND
(R.venue = ‘H’) <> (RE.venue = ‘H’)
AND
R.date <= RE.date
) as RunGroup
FROM
resultengine RE
) A
WHERE
venue = ‘H’
AND
result=‘W’
GROUP BY
result, RunGroup
ORDER BY
Games[/php]
It’s not working, however - the streaks it returns are being truncated and I can’t see for what reason they are. And I know they are because I’ve done manual counts of the data based on results that are returned. Sorry if this post is a bit long, but what am I not doing to get the desired result. Let me know if more info is needed.