Jump to content

Recommended Posts

Hi all,

Does anyone know how I could alter the MYSQL code to select the last 5 games each Team has played to create a table of using the last 5 games to show current form?

 

My current code is as follows:

    select 
    team, 
    count(*) played, 
    count(case when scor1 > scor2 then 1 end) wins, 
    count(case when scor2> scor1 then 1 end) lost, 
    count(case when scor1 = scor2 then 1 end) draws, 
    sum(scor1) scor1, 
    sum(scor2) scor2, 
    sum(scor1) - sum(scor2) goal_diff,
    sum(
          case when scor1 > scor2 then 3 else 0 end 
        + case when scor1 = scor2 then 1 else 0 end
    ) score 
from (
  select  txtechipa1 team, scor1, scor2 from footballtest INNER JOIN Leagues ON LEFT(footballtest.codmeci, 4) = Leagues.code where Leagues.Code = '0101' and   footballtest.sezonul = '19' and datameci < CURDATE()  
  union all
    select  txtechipa2, scor2, scor1 from footballtest  INNER JOIN Leagues ON  LEFT(footballtest.codmeci, 4) = Leagues.code where Leagues.Code = '0101' and   footballtest.sezonul = '19' and datameci < CURDATE()  
) a
group by team
order by score desc , goal_diff  

 

Link to comment
https://forums.phpfreaks.com/topic/308572-football-league-table-last-5-matches/
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.