SELECT months, total, ruzhu, cancels
FROM (SELECT to_char(ordertime,'mm') as months,count(*) as total, 0 ruzhu, 0 cancels
FROM tb_order where B_ID = '1'
GROUP BY to_char(ordertime,'mm')
UNION ALL
SELECT to_char(ordertime,'mm') as months, 0 total, count(*) as ruzhu, 0 cancels
FROM tb_order where B_ID = '1' and (status = 1 or status = 2 or status = 3)
GROUP BY to_char(ordertime,'mm')
UNION ALL
SELECT to_char(ordertime,'mm') as months, 0 total, 0 ruzhu, count(*) as cancels
FROM tb_order where B_ID = '1' and (status = 6 or status = 7)
GROUP BY to_char(ordertime,'mm'))
查询结果如下图
我想想要的结果是
moths total ruzhu cancels
08 1 1 0
07 7 5 2