Hi! I got a table:
CREATE TABLE SampleTable (
A_ID NUMBER NOT NULL,
A_COL_VAL VARCHAR2(128 BYTE),
TABLE_INSERT_TIME TIMESTAMP(2) DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP),
)
TABLESPACE USERS
STORAGE (INITIAL 64 K
NEXT 1 M
MAXEXTENTS UNLIMITED)
LOGGING;
Need to get the last N records for the last X days.
What's the most efficient query I can write? The table
has over 2 mln records and I cannot change the design.
- If there are more than N records in the last X days, only N should be retrieved.
- If there are fewer records than N in the last X days, all records should be retrieved.
Is subquery the way to go? Rank?
MAX_CNT NUMBER := 5000;
LAST_NUM_DAYS NUMBER:= 150;
Infinite thanks in advance,