PostgreSQL: Grouping then filtering table, with condition for nonexistence
问题 In PostgreSQL, I have a table that, abstractly, looks like this: ╔═══╦═══╦═══╦═══╗ ║ A ║ B ║ C ║ D ║ ╠═══╬═══╬═══╬═══╣ ║ x ║ 0 ║ y ║ 0 ║ ║ x ║ 0 ║ x ║ 1 ║ ║ x ║ 1 ║ y ║ 0 ║ ║ x ║ 1 ║ z ║ 1 ║ ║ y ║ 0 ║ z ║ 0 ║ ║ y ║ 0 ║ x ║ 0 ║ ║ y ║ 1 ║ y ║ 0 ║ ╚═══╩═══╩═══╩═══╝ I want to transform it in a query into this: ╔═══╦═══╦══════╗ ║ A ║ B ║ D ║ ╠═══╬═══╬══════╣ ║ x ║ 0 ║ 1 ║ ║ x ║ 1 ║ null ║ ║ y ║ 0 ║ null ║ ║ y ║ 1 ║ 0 ║ ╚═══╩═══╩══════╝ …such that: The input table’s rows are grouped by A and B, and