I am on postgres/greenplum and I have a query result like this :
e1 | e2 ------------------- | ------------------- 2017-01-01 00:00:00 | 2017-01-02 00:00:00 2017-01-01 00:00:00 | 2017-01-03 00:00:00 | 2017-01-03 00:00:00
I want to transform this into following :
timestamp | e1 | e2 ---------------------+----+---- 2017-01-01 00:00:00 | 2 | 0 2017-01-02 00:00:00 | 0 | 1 2017-01-03 00:00:00 | 1 | 1
Here the first column contains all the unique timestamps and rest of the columns respective count of occurrences for each event (e1, e2 ...).
NOTE: The dataset is very large so transformation in application side is very costly.
You could have two aggregate queries, on for each column, and use a full outer join to combine the two: