I am trying to generate a report that shows records from a single table that meet either of two conditions:
1) “D” = ‘ERR’ and the record is less than a week old.
— OR —
2) “D” = ‘X’ OR ‘Y’ AND the record is more than one hour old.
I have started out with requirement #1, but I don’t know how to perform both requirements in the same query with the right logic applied. For the record to be display on the report, either of the two conditions can be applicable, and the condition #2 actually needs to have an OR operator as well.
I’m probably going to change this report to work from the past X hours (1/2/4/8) as well, but I am sure another post on this site addresses that question.
SELECT "A", "B", "C"
FROM Schema."Table"
WHERE "D"='ERR' AND TimeStamp >= (CURRENT_TIMESTAMP - 7 DAYS)
ORDER BY TimeStamp DESC
If you use
()you can group your conditions together to get the desired output: