select ( select SUM(e.summ)
from myevents.event as e
LEFT JOIN myevents.type as t on t.id = e.type
WHERE (e.dtr >= '2018-04-01') AND (e.dtr <= '2018-04-31') AND
(t.id = 1)) as 'dohod',
(select SUM(e.summ)
from myevents.event as e
LEFT JOIN myevents.type as t on t.id = e.type
WHERE (e.dtr >= '2018-04-01') AND (e.dtr <= '2018-04-31') AND
(t.id = 2)) as 'rashod';
select ( select SUM(e.summ)
from myevents.event as e
LEFT JOIN myevents.type as t on t.id = e.type
WHERE (e.dtr >= '2018-05-01') AND (e.dtr <= '2018-05-31') AND
(t.id = 1)) as 'dohod',
(select SUM(e.summ)
from myevents.event as e
LEFT JOIN myevents.type as t on t.id = e.type
WHERE (e.dtr >= '2018-05-01') AND (e.dtr <= '2018-05-31') AND
(t.id = 2)) as 'rashod';
select DATE_FORMAT(event .dtr,"%Y-%m"), event.type, sum(event.summ),
from event
where event dtr between ... and ...
group by DATE_FORMAT(event .dtr,"%Y-%m"), event.type, sum(event.summ)
SELECT
SUM( CASE WHEN `type` = 1 THEN `summ` END) 'dohod',
SUM( CASE WHEN `type` = 2 THEN `summ` END) 'rashod',
MONTH(dtr) 'month'
FROM myevents.event
WHERE
YEAR(dtr) = 2018
AND `month` BETWEEN 4 AND 5
GROUP BY `month`