Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL to check for Re-Occurring Event.

Mr.JondeeDec 15 2020 — edited Dec 16 2020

Hello All ,
Please will need help in solving below business requirement, excerpts below...
Thanks very much

Oracle version: 12.2.0.1.0
Problem:
EVENTS_FACT_TAB.NEW_EVENT_FLAG - Should tell us if the viewing event was the first view event for the given device
EVENTS_FACT_TAB.REJUV_EVENT_FLAG - Should tell us if the viewing event was the first view event after a specified absence for the given device
for the past 364 Days

Notes for implementation :
First check the Lookup_dim table to see if the device_id is present or not
We should be able to handle multiple view events on a given day for a given device. Only the FIRST view event of the day should be tagged as "NEW",
not the rest of the view events from the same day
This applies to REJUV_EVENT_FLAG as well.
DDL and DML:
rejuv.txt (6.22 KB)Expected Result:
image.png
Current Attempt: To resolve_New_event_flag
--load below value into temp table
SELECT FACT_ID,
DEVICE_ID,
VIEW_START,
VIEW_END,
NEW_EVENT_FLAG,
REJUV_EVENT_FLAG ,
ROW_NUMBER () OVER (PARTITION BY device_id ORDER BY VIEW_END DESC) RANK_DEVICE
FROM EVENTS_FACT_TAB;

--update fact table
UPDATE EVENTS_FACT_TAB a
set a.NEW_EVENT_FLAG = 1
where a.device_id in (select b.device_id from Temp_table where rank_device = 1)

This post has been answered by Frank Kulash on Dec 16 2020
Jump to Answer
Comments
Post Details
Added on Dec 15 2020
12 comments
424 views