I need help to make the stairs.
Here is the info:
Tables:
cricket_teams(id, name) cricket_matches(id, hometeam, awayteam, format, season, winner) cricket_teamperformance(id, matchid, team, innings, score)
(there are other fields in the tables that are not needed for this query)
I need to get it so that it gives me wins , draws (where the winner = 0), losses, FIP (when the team scores more points in the first innings), BP (in this case only win) and Points (in bold). I have a request, but I have a few questions. I canโt understand how to get draws and losses, and also not to get teams that did not win the game. Here is what I have:
SELECT b.team, b.name, COUNT(c.wins) as W, count(b.name)*2 as FIP, COUNT(c.wins)*2 as BP, COUNT(c.wins)*4+(count(b.name)*2)+(COUNT(c.wins)*2) as Pts FROM (SELECT a.name, a.score, a.matchid, a.team FROM (SELECT cricket_teams.name, score, matchid, team FROM `cricket_teamperformance` LEFT JOIN cricket_teams ON cricket_teamperformance.team = cricket_teams.id INNER JOIN cricket_matches ON cricket_teamperformance.matchid = cricket_matches.id WHERE cricket_matches.format=3 AND cricket_teamperformance.innings = 1 AND cricket_matches.season = 1 OR cricket_matches.format=3 AND cricket_teamperformance.innings = 2 AND cricket_matches.season = 1 ORDER BY matchid, score DESC) as a GROUP BY matchid) as b, (SELECT COUNT(winner) as wins, cricket_teams.name FROM cricket_matches LEFT JOIN cricket_teams ON cricket_matches.winner = cricket_teams.id WHERE format = 3 AND season = 1) as c GROUP BY b.name ORDER BY Pts DESC
And this returns:
team name W FIP BP Pts 4 Chargers 2 4 4 16 2 Hawks 1 2 2 8 1 Ninjas 1 2 2 8
It should look like this (P - matches played, D - draws, L - losses):
team name PWDL FIP BP Pts 4 Chargers 2 2 0 0 4 4 16 2 Hawks 2 1 0 1 2 2 8 1 Ninjas 2 1 0 1 2 2 8 3 Wolves 2 0 0 2 0 0 0
There is another team, Wolves, who have not won any of their two games. I also need to get these draws and losses. thanks in advance
* This is a multi-year cricket in which teams can have up to two innings per match. SQL Fiddle: http://sqlfiddle.com/#!2/26e41/2