Skip to content
Advertisement

Variable in dateadd function snowflake

I have a query like this:

It gives this error: Single row subquery returns more than one row.

Is there a way to pass a variable in the 3rd argument of dateadd function? Because my cte will return many min_date based on the group by clause. TIA

Advertisement

Answer

Yes, sub-select in SELECT need to only return one row, you have many rows in your CTE.

You query makes more sense to me if you did something like this:

but if your CTE was changing to be like this:

this would work, as there is only one min_date value returned.

OR you could find the smallest of the min_dates like:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement