SELECT value,
SUM(value = val1) total_1,
SUM(value = val2) total_2
FROM ( SELECT val1 value FROM test
UNION
SELECT val2 FROM test ) total
CROSS JOIN test
GROUP BY value
ORDER BY value;
select coalesce(t1.col1, t2.col2) as "группировка"
, coalesce(t1.c, 0) as "кол-во_1"
, coalesce(t2.c, 0) as "кол-во_2"
from (select col1, count(*) c from test group by col1) t1
full join
(select col2, count(*) c from test group by col2) t2 on t1.col1 = t2.col2
order by 1
;