I have my two tables with their 2 columns and what I want to obtain is the separate sum of the total of the plotting table and separately the total of the technical service table, as well as obtaining the month number of plotting and technical service, but separately .
database tables
|*ot_ploteo* | |*ot_servicio_tecnico* |
|--------------| |-----------------------|
|Total_OTPloteo| |Total_OTServicioTecnico|
|Fecha_OTPloteo| |Fecha_OTServicioTecnico|
These are the data stored in each of them
|Total_OTPloteo|Fecha_OTPloteo| |Total_OTServicioTecnico|Fecha_OTServicioTecnico|
|7.00 |2021-02-07 | |44.00 | 2021-02-06 |
|12.00 | 2021-02-05 |
What I want to get is the following
|totalPloteo|mesPloteo|totalSt|mesSt|
|7.00 |2 |56.00 |2 |
My test code not working
SELECT MONTH
( Fecha_OTServicioTecnico ) AS mes,
SUM( Total_OTServicioTecnico ) AS monto,
MONTH ( Fecha_OTPloteo ) AS mesPloteo,
SUM( Total_OTPloteo ) AS montoPloteo
FROM
`ot_servicio_tecnico`,
`ot_ploteo`
WHERE
`Fecha_OTServicioTecnico` >= '2021-01-01'
AND `Fecha_OTServicioTecnico` <= '2021-12-31' AND `Fecha_OTPloteo` >= '2021-01-01'
AND `Fecha_OTPloteo` <= '2021-12-31'
AND `Estado_OTServicioTecnico` = 1
AND `Estado_OTPloteo` = 1
GROUP BY
`mes`
From the code that I have, these results work well, which I hope to obtain or at least in the first instance mesPloteo , totalSt , mesSt , but from totalPloteo it is as if 7.00 were added again or multiplied but the result that I get is 14.00 and not only 7.00.
From what you say you want to get, I have a feeling you're looking for something like this:
To get:
This way you connect both intermediate results by the data they have in common, which is the month.
I provide you with the dataset for the checks: