Skip to content
Advertisement

Redshift SQL statement that will return 1 or 0 if the select statement returns any rows

I have the following select statement in Redshift that will return rows with certain values if the condition inside is met. I want to transform this into a DQ check which will return 1 (True) if no rows ae returned or 0 if any row is returned, but I do not know where I should apply the case statement. Here is the select statement:

Can you please offer me some ideas for this?

Advertisement

Answer

First, Redshift supports booleans, so case is not needed. Second, do the filtering on the date before the aggregation. This is usually faster.

Then, you can filter by the count using a having clause, so no subquery is needed:

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