Skip to content
Advertisement

Check for condition in GROUP BY?

Take this example data:

I need an SQL statement that will group all the data but bring back the current status. So for ID 1 the group by needs a condition that only returns the Completed row and also returned the pending rows for ID 2 and 3.

I am not 100% how to write in the condition for this.

Maybe something like:

The problem with this is the resulting data would look like:

But I need:

What can I do to check for the Completed status so I can only return Completed in the group by?

Advertisement

Answer

To use Date as ‘last row indicator’, you can:

Result:

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