There are many ways to achieve what you want. Considering that your table has the following structure ..
CREATE TABLE blabla (user_id INT,activity_type VARCHAR,interested_rooms VARCHAR);
INSERT INTO blabla VALUES (1,'views','1,2'),
(1,'application','1'),
(1,'search','3,2');
.. you could try a CTE
..
WITH j AS (
SELECT DISTINCT user_id, unnest(string_to_array(interested_rooms,',')) AS rooms
FROM blabla ORDER BY rooms
)
SELECT user_id, array_agg(rooms) AS interested_rooms
FROM j GROUP BY user_id
.. that would return the result you want
user_id | interested_rooms
---------+------------------
1 | {1,2,3}
Note that the usage of the functions unnest
and string_to_array
will depend on the data type of the column interested_rooms
which wasn't provided in your question. But it should give you an orientation of what to do. Good luck!