test=*# select * from t1;
lgr | anzahl
-----+--------
c1 | 7
s3 | 6
p4 | 4
q2 | 5
(4 rows)
test=*# select * from t2;
lgr | anzahl
-----+--------
c1 | 9
s3 | 8
p4 | 7
q2 | 6
(4 rows)
test=*# select '2016-03-03'::date as datum, sum(case when lgr = 'c1' then anzahl else 0 end) as c1, sum(case when lgr='s3' then anzahl else 0 end) as s2 from t1 group by1 union all select '2016-03-04'::date, sum(case when lgr = 'c1' then anzahl else 0 end) as c1, sum(case when lgr='s3' then anzahl else 0 end) as s2 from t2 group by 1;
datum | c1 | s2
------------+----+----
2016-03-03 | 7 | 6
2016-03-04 | 9 | 8
(2 rows)