SELECT ID,
CASE WHEN listagg(
DISTINCT col_1,',') WITHIN GROUP(ORDER BY col_1)= '' THEN 'null'
ELSE (lower(LISTAGG(distinct col_1,',') WITHIN GROUP ( ORDER BY col_1))) END AS Col_001
FROM
(SELECT distinct B.ID, date, timestamp,
TRY_CAST(pno as INTEGER) as pno,
REGEXP_REPLACE(col_1,'\http.*$|null', '') as col_1
FROM
table1 B LEFT JOIN table2 D ON D.ID=B.ID
WHERE B.ID IN('5871162','35915895')
and date='2021-11-02'
ORDER BY pno)
GROUP BY ID;
When I run the above query, I'm getting results like
ID COL_001
5871162 ,monthend_offer
35915895 dec_cashback,dec_offer
If I replace comma with empty string, the result will be like mentioned below and that is not the excepted result
5871162 monthend_offer
35915895 dec_cashbackdec_offer
I want to replace only the comma ',' from the first record. The record should display like below:
5871162 monthend_offer
35915895 dec_cashback,dec_offer
I want to replace only the LEADING comma
Any guidance on how to implement this?