I'm basically trying to write a query where if an event occurs within the last 200 days, it will display column values for A, B, C, D, E, F But in this same query, if an event does not occur within the last 200 days (201 days & beyond), it will only display values in columns A and B.
My current query I tried to do two select statements using the UNION statement. I tried to do a CASE statements for column C, D, E and F for the SELECT after the UNION, but I could not get it to work.
This current query displays all values for all columns regardless of if it occurred < or > 200 days.
SELECT te.columna,
c.columnb,
te.columnc,
v.columnd,
v.columne,
v.columnf
FROM table1 te, table2 c, table3 v
WHERE te.columng_id=c.columng_id
AND v.columne=te.columne
AND te.columnc > sysdate-200
UNION
SELECT te.columna,
c.columnb,
te.columnc,
v.columnd,
v.columne,
v.columnf
FROM table1 te, table2 c, table3 v
WHERE te.columng_id=c.columng_id
AND v.columne=te.columne
AND te.columnc < sysdate-200
te.columnc > sysdate-200andte.columnc < sysdate-200you're missing a potential value. It probably won't affect the query at all but one of those operators should be "or equal to". That is, you can use "greater than" (>) together with "less than or equal to" (<=) or "less than" (<) with "greater than or equal to" (>=). You might also want to use theTRUNC()function to truncate the date.