I have a vehicle table with field with date of purchase and I can retrive info with
SELECT
MONTH(vehiculo.fecha_compra) mes,
SUM(vehiculo.precio_compra) importe,
COUNT(*) cantidad
FROM
vehiculo
WHERE
YEAR(vehiculo.fecha_compra) = '2024'
GROUP BY
MONTH(vehiculo.fecha_compra);
And I have a second table with data about sales that can be query like:
SELECT
MONTH(propuesta.fecha) mes,
SUM(propuesta.cotizacion) importe,
COUNT(*) cantidad
FROM
propuesta
WHERE
estado = "Vendido" AND YEAR(propuesta.fecha) = '2024'
GROUP BY
MONTH(propuesta.fecha)
I would have a combination between two tables to obtain something like:
Main problem is that there can be some months with purchassing but not with sales.



You need a full outer join. However, MySQL [still] does not implement them. You can simulate it by union-ing a left join with an anti-semi-join. You can do:
If there will never be months with sales an no purchases you can simplify the query by removing the tail of it (that starts with
union all).