Search code examples
concatenationsnowflake-cloud-data-platform

Snowflake concatenate Name's based on Start Time


I'm attempting to concatenate names from the Name column based on start time found in the Start Time column as found in the following Table Data.

The end result should concatenate the name from rows 1 (Holiday Sale) and 2 (New Year) because the Start Time's fall on the same date and time. So it should read similar to "Holiday Sale, New Year" with the Start Date column showing "2019-12-26 00:00:00".

I've tried to alter several queries that were originally used to merge dates based on a name or ID so that they would merge (concatenate) names based on the dates. None of these proved successful and resulted in a "Timeout Error". Here's a couple of queries I've attempted: - start date end date combine rows - Merge overlapping date intervals


Solution

  • I believe LISTAGG https://docs.snowflake.net/manuals/sql-reference/functions/listagg.html is something you are looking for. Try

    select listagg(name, ', '), start_time from table group by start_time;