STRING_AGG + Explanation
This query will show the disired result: \n select sell_date, count(distinct(product)) as num_sold,\n STRING_AGG(product,\',\') within group (order by product) 
This query will show the disired result: \n select sell_date, count(distinct(product)) as num_sold,\n STRING_AGG(product,\',\') within group (order by product) as products\nfrom\n(SELECT DISTINCT sell_date, product FROM Activities) T\ngroup by sell_date\norder by sell_date\n\nthe reason for using this part ((SELECT DISTINCT sell_date, product FROM Activities) T) is that \nneed for bring distinct value on product name. (SQL server can not understand Distinct in the STRING_AGG, so need some query to send distinct value)\n\nin addition, postgres sql can understand Distinct in STRING_AGG, so you can use this query instead of top in postgrest sql:\n\n select sell_date, count(distinct(product)) as num_sold,\n STRING_AGG(distinct(product), \',\'\n order by product)\n as products\nfrom Activities\ngroup by sell_date\norder by sell_date\nAlso you can check this link: \nhttps://gregdodd.me/2021/08/24/distinct-list-in-string_agg/\n\nPlease UpVote if it was Helpful\n\n
['MS SQL Server']