I have data in my postgres table like this.
I want to get a result like this.
I tried nested query like this. I only did rows where column1 is having multiple values in column2. For example, C3, c4 have just one each, I’d like to skip that.
select column1, column2, dCount
from (select column1, column2, count(column3) as dCount
from schema.table
where column1 != 0
group by column1, column2) t
group by t.column1, t.column2, t.dCount
having count(t.column2) > 0;
But I am getting 0 rows out.
2
Answers
You can do it using
group by
andcount()
andHAVING COUNT(column3) > 1
to get only records with multiple data :Demo here
We can use the following two step aggregation query: