Skip to content
Advertisement

SQL GROUP BY where partitions meet condition

Consider following table:

I want to group by var_a in such a way, that each group would have in it var_b = ‘123’ and var_b = ‘456’. That is, I want to obtain “abcd” and “ijkl” in the set of results. How do I do that?

Advertisement

Answer

You can filter the table and group by var_a:

The condition in the having clause makes sure that both '123' and '456' exist for the same var_a.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement