Skip to content
Advertisement

SQL Query for Events table

I have an event table in Postgres, with this structure:

This works as a log, so all entries are immutable, change is status will be another INSERT.

I want to efficiently extract all events which have status CREATED, but not DONE.

Advertisement

Answer

I assume that you want ITEMs that meet the conditions. If so:

This uses the fact that 'CREATED' < 'DONE' alphabetically. You can also use conditional aggregation:

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