Add data from tables ID by ID in MySQL [duplicate]

0

I have 2 tables in which I record baseball statistics for 2016 and another for 2017.

I have not been able to formulate a Query that adds the statistics of the 2 years of each player and shows it to me in the same way they are shown in the image.

    
asked by Granedoy 11.01.2018 в 02:32
source

2 answers

0

To relate tables you could use inner join

   SELECT tabla.dato,
   ([columna 1] + [columna 2] as tablas_totales
   FROM
   (SELECT [dato],
   sum([campo1]) AS "columna 1"
   FROM [dbo].[Ejemplo1]
   GROUP BY dato) as tabla_1
   inner join
   (SELECT [dato],
   sum([campo2]) AS "columna 2"
   FROM [dbo].[Ejemplo2]
   GROUP BY dato) as tabla_2
   on tabla_1.dato = tabla_2.dato
   ORDER BY tabla_1.dato
    
answered by 11.01.2018 в 03:03
0

You can do the query to the database something like that

  

SELECT ID, YEAR, NAME, SUM (ATTRIBUTE1), SUM (ATTRIBUTE2), SUM ... FROM (TABLE1) INNER JOIN   (TABLE2) USING (ID) WHERE YEAR > = (year_initial) AND YEAR < = (year_final)   GROUP BY (ID)

the variables year_final and year_initial specify you.

    
answered by 11.01.2018 в 03:33