Some friends and I are writing a php site where we can log our matches, create tournaments and log matches for these tournaments etc.
We hit a wall with displaying our matches for a certain tournament. We tried doing it with php but that messes up the tournament table totally
We have a table called matches where we have following columns:
ID player1ID player2Id team1ID team2ID ScorePlayer1 ScorePlayer2 Date TournamentID
Now we want to make tables like:
GPl W L D + - +/- Pnts
Nielsen 6 1 3 2 3 6 -3 13
Chibax 6 2 1 3 4 3 1 9
Verre 6 1 3 2 3 6 -3 5
Hermie 6 4 1 1 7 2 5 5
But with php the rows with W L D and points never match , the whole table is weird.
Anyone have an idea of how we can do this with an SQL command ? (for non-soccer people: wins x 3 pnts Draws x 1 pnts losses 0 pnts
I don’t know if mysql with php still shuns subqueries but the following might have a chance of working. I’ll test it later on as I don’t have the time at the moment. I just though I’d give you some ideas.
If the subqueries do not work then you could create a view of the subquery and proceed from there.
I’m also not sure if mysql supports column names that are expressed using double quotes (
"+/-")The basic idea is to select the score separately for home games and visiting games. Aggregate functions allow usually allow case statements within them that allows you to do a bit magic.
Edit: I forgot to order the results. You need a bit magic if you want to use matches between players A and B to order the results in case of a tie.