T-SQL | Simple Solution | WITH & COUNT & STRING_AGG & WITHIN
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```sql\nWITH t AS (SELECT DISTINCT * FROM Activities)\n\nSELECT \n    t.sell_date,\n    COUNT(t.product) AS num_sold,\n    STRING_AGG(t.product, \',\') WITHIN GROUP (ORDER BY t.product) as products\nFROM t\nGROUP BY sell_date\nORDER BY sell_date\n```\n
['Database', 'MS SQL Server']