Reputation: 273
I'm fairly new to sql, and was wondering if there was a simple way to query a database for pairs of entries. Specifically, In this database table, there are a bunch of entries that describe various events. A particular event will first appear (in one row) as acknowledged, and the next entry for the same event, are marked as processed. I want to know if there's an elegant way to get each such pair of entries, perform some calculations on them, and then move onto the next pair until there are no more entries.
Upvotes: 0
Views: 62
Reputation: 1270653
You can use a join like this:
select *
from events a
events p
on a.eventid = p.eventid and
a.status = 'acknowledged' and
p.status = processed;
This will bring back the pairs of rows. Of course, this is subject to lots of conditions, but it is a general way to approach what you are asking for.
Upvotes: 1
Reputation: 49896
W/o any schema one can only speak in generalities, but you could do a join to get appropriate pairs of rows.
Upvotes: 0