I have a rather large query I've been building for a report. It appears all is working well, except for one section. It shouldn't be this hard, but for some reason I'm not getting that section to work. Perhaps I've simply been working on the report for too long, but hopefully someone out there can help.
For that section, I have a table called valid_alerts. It has data much like the following (in this example, I made 'hostname' values easier to read and remember):
===============
alert_date hostname
===============
11/13/09 A
11/12/09 A
11/11/09 A
11/10/09 A
---------------------------
11/06/09 A
11/05/09 A
---------------------------
11/06/09 B
11/04/09 B
===============
I am trying to get records where alert_date has no consecutive dates above it. For instance, the result from the example above would be as follows:
===============
alert_date hostname
===============
11/13/09 A
---------------------------
11/06/09 A
---------------------------
11/06/09 B
===============
Obviously, there is much more data than given in this example.
By the way, 'alert_date' and 'hostname' together will uniquely identify a record. I tried the following SQL, thinking it would work. However, it appears as though it is not working at all:
SELECT alert_date, hostname
FROM valid_alerts v_a
WHERE (alert_date || ' ' || hostname) NOT IN (SELECT alert_date || ' ' || hostname AS combined
FROM valid_alerts
WHERE alert_date = v_a.alert_date - 1)
If anyone could help me correct my SQL or think of a better version, I would greatly appreciate your help!!
For that section, I have a table called valid_alerts. It has data much like the following (in this example, I made 'hostname' values easier to read and remember):
===============
alert_date hostname
===============
11/13/09 A
11/12/09 A
11/11/09 A
11/10/09 A
---------------------------
11/06/09 A
11/05/09 A
---------------------------
11/06/09 B
11/04/09 B
===============
I am trying to get records where alert_date has no consecutive dates above it. For instance, the result from the example above would be as follows:
===============
alert_date hostname
===============
11/13/09 A
---------------------------
11/06/09 A
---------------------------
11/06/09 B
===============
Obviously, there is much more data than given in this example.
By the way, 'alert_date' and 'hostname' together will uniquely identify a record. I tried the following SQL, thinking it would work. However, it appears as though it is not working at all:
SELECT alert_date, hostname
FROM valid_alerts v_a
WHERE (alert_date || ' ' || hostname) NOT IN (SELECT alert_date || ' ' || hostname AS combined
FROM valid_alerts
WHERE alert_date = v_a.alert_date - 1)
If anyone could help me correct my SQL or think of a better version, I would greatly appreciate your help!!