I have a table in the following format :

| owner\_id | question | response | created\_at |
| --- | --- | --- | --- |
| 1 | dog\_name | Rex | 2021-05-31 |
| 1 | cat\_name | Old Kitty | 2021-05-01 |
| 1 | cat\_name | New Kitty | 2021-05-30 |
| 2 | cat\_name | Bella | 2021-05-28 |
| 3 | bird\_name | Birdy | 2021-05-28 |

And I would like to be able have the list of owner with each pet's name :

| owner\_id | dog\_name | cat\_name | bird\_name |
| --- | --- | --- | --- |
| 1 | Rex | New Kitty | NULL |
| 2 | NULL | Bella | NULL |
| 3 | NULL | NULL | Birdy |

I have manage to list all the data that I need with the following query :

```sql
SELECT DISTINCT ON (owner_id, question) owner_id, question, response
FROM pets
ORDER BY owner_id, question, created_at DESC

```

It output what I need. However, I need to transpose the data and having `dog_name` / `cat_name` / etc. (finite list of pet type) in column.