I am using following query in Snowflake to get the SKU # and their processing dates using LISTAGG function
SELECT DISTINCT SKU, LISTAGG(DISTINCT Date, ';')
FROM SKU_Data
I want to use the DESC for the LISTAGG function so I can have dates in descending order. I modify the upper query into following
SELECT DISTINCT SKU, LISTAGG(DISTINCT Date, ';' DESC)
FROM SKU_Data
But I having an error.
You need to use WITHIN GROUP (ORDER BY date DESC)
.
SELECT
sku,
LISTAGG(DISTINCT date, ';') WITHIN GROUP (ORDER BY date DESC) AS date_list
FROM sku_data
GROUP BY sku