I want to join these two queries into one and add the two results:
SELECT torneo_organizacion, jugador_a, SUM( puntos_jugador_a ) AS total FROM game
WHERE torneo_organizacion = "MZF-CAB" AND jugador_a = 125
AND fecha_partido >= ( CURDATE( ) - INTERVAL 365 DAY )
SELECT torneo_organizacion, jugador_b, SUM( puntos_jugador_b ) AS total FROM game
WHERE torneo_organizacion = "MZF-CAB" AND jugador_b = 125
AND fecha_partido >= ( CURDATE( ) - INTERVAL 365 DAY )
You can have both results, as player A and as player B:
In the
SELECT
we have two sums, which will add the content ofpuntos_jugador_a
orpuntos_jugador_b
only in case the player we are adding is thea
or theb
(sum0
in another case).You can also get the total data using the following query:
In this case, add the points
puntos_jugador_a
if it is the playera
orpuntos_jugador_b
otherwise (it is assumed that it will be theb
).Both queries share the same
WHERE
:In which the records whose
jugador_a
orjugador_b
the one we are analyzing are searched.You can see the operation online at the following link:
SELECT SUM( puntos_jugador_a + (SELECT SUM( puntos_jugador_b )
AS total FROM game WHERE torneo_organizacion = "MZF-CAB" AND jugador_b = 125 AND fecha_partido >= ( CURDATE( ) - INTERVAL 365 DAY ))) AS total FROM game WHERE torneo_organizacion = "MZF-CAB" AND jugador_a = 125 AND fecha_partido >= ( CURDATE( ) - INTERVAL 365 DAY )
If this query is correct, the only thing it will give you is the sum of the points, which is what you want to obtain. I don't know if it's the best way. Also, it comes out of the code you provided, so if your queries were working, they should work.
Subject I recommend studying:
SUBQUERIES
https://www.youtube.com/watch?v=rGPb5E1UAJA
https://www.youtube.com/watch?v=lCpMJ2LFdLg