By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table yourtable (country varchar(100), value varchar(100));
insert into yourtable values ('FR',NULL);
insert into yourtable values ('FR',1);
insert into yourtable values ('FR',3);
insert into yourtable values ('MA',5);
insert into yourtable values ('MA',NULL);
insert into yourtable values ('MA',4);
insert into yourtable values ('ES',9);
insert into yourtable values ('ES',10);
insert into yourtable values ('ES',NULL);
9 rows affected
SELECT country, value FROM yourtable;
country | value |
---|---|
FR | null |
FR | 1 |
FR | 3 |
MA | 5 |
MA | null |
MA | 4 |
ES | 9 |
ES | 10 |
ES | null |
SELECT country, STRING_AGG(COALESCE(value,'NULL'),',') AS value
FROM yourtable
GROUP BY country
ORDER BY country;
country | value |
---|---|
ES | 9,10,NULL |
FR | NULL,1,3 |
MA | 5,NULL,4 |