Postgres Query Help - Determine Unacked Events

I'm try to write query that will allow me to see how many alarm events when unacknowledged using Postgres by comparing event types against event id's. I'd like to know how many event id's do not have an entry with an event type of 2. For example, the table below would return one event that went unacknowledged.

eventid eventtype
eventid1 1
eventid1 0
eventid2 2
eventid2 0
eventid2 1

Thanks in advance for any help.

I was able to use a CROSSTAB() function in the query:

SELECT *
FROM CROSSTAB('select eventid,
                      eventtype,
                      eventtype as value
                      FROM alarm_events
                      WHERE eventtype in (0,2)') AS CT (eventid varchar(255), "type0" int, "type2" int)
WHERE type2 IS NULL
1 Like