I need some help in constructing an oracle query that will pull values for 2 days previous.
The timestamp column (number) values look like this 201106210000.
The other date like number columns have values like this:
year=2011 quarter=2 month=6 day=20
Where does it make sense to do the date arithmetic? using the timestamp or should I used these other calendar columns?
The table also has these date attributes:
Name Null? Type
----------------------------------------- -------- ----------------------------
YEAR NUMBER
QUARTER NUMBER
MONTH NUMBER
DAY NUMBER
HOUR NUMBER
TIMESTAMP NUMBER
CNT_N NUMBER
First, this table is a crappy way to store dates (which hopefully you are aware of). Why not either a DATE or TIMESTAMP column?
If that is out of your control, I would recommend using a to_date() on a concatenation of the YEAR, MONTH, and DAY columns so you have an actual DATE to work with. Something like:
Since your columns aren’t real date columns you would need a function-based index to avoid a full table scan using this method.