I have a MySQL database with 3 tables.
- Table player
P_id = content (1, 2, 3,)
P_name = content (Spieler1name, Spieler2name, Spieler3name)
- Table tournament
T_id = content (1, 2)
T_date = content (2018, 2019)
T_players = content (123, 123)
- Table Games
G_id = content (1, 2)
G_tournament_id = content (T_id from table tournament)
G_player_away = Content (as an example user id 1)
G_player_home = content (as an example user id 2)
G_player_away_points = Content (11)
G_player_home_points = Content (8)
The Games table has even more data.
Now I want to create a table with PhP as ranking.
Place name points
Spieler1name 11
Spieler2name 8
Spieler3name 4
....
Can someone tell me how the php query from the mysql database works? I tested this but it doesn't work.
SELECT SUM(G_player_away_points) AS total FROM Games
UNION
SELECT SUM(G_player_home_points) AS total FROM Games
GROUP BY G_player_away
In the code above, he also sums the points from the opponent. This is of course not correct, it should only the points obtained by him appear in the output with php table. Furthermore you have to get the name from the table players. Can someone help me?