I have the following table called purchases

of which I need to obtain a total sum grouped by month. Just to give an example of what I'm trying to do, I have this query.

```
SELECT * FROM (SELECT DISTINCT MONTH(creado) as meses,
IFNULL(SUM(total),0) as total_mes FROM ventas WHERE YEAR(creado) =
'2018' AND idsucursal='1' AND estado='Enviado' GROUP BY meses ORDER BY
meses DESC) as ventas,(SELECT DISTINCT MONTH(fecha_compra) as mesess,
IFNULL(SUM(total),0) as total_mes_compras FROM compras WHERE
YEAR(fecha_compra) = '2018' AND idsucursal='1' AND estado='Aceptado'
```

GROUP BY mesess ORDER BY mesess DESC) as purchases GROUP BY months, mesess

and the result I get is

and the result I want to obtain would be like that.

Please if you can help me, I'm already breaking my head. Thanks