Thank you Sir.
so this OVER keyword is part of Oracle analytics? thats what I got when I googled.
One last question:
Attached snapshot is the output from that query. So its showing every 3 records.
The actual requirements is something like,
Group the IDs
Show the most recent login_time and the count betweent he date range
sp for every ID, just one Row, most recent login time (The 3rd row in the snapshot) and the count.
Also, why the column headers have names of the syntax? Can we make those little simpler, something like ID, LOGIN_TIME and COUNT?
Main Topics
Browse All Topics





by: sdstuberPosted on 2009-11-03 at 09:32:46ID: 25731355
LAST_VALUE(login_date) OVER (PARTITION BY id ORDER BY login_date)
the "over" clause creates a window of rows. the "partition by" clause groups the rows by ID and sorts them by login_date so each window will only have data for a single id.
then LAST_VALUE simply returns whatever is the last login_date within that window, which will be the most recent value
the COUNT(*) OVER() does the same thing but because the OVER() clause is empty, the window spans the entire result set