Link to home
Start Free TrialLog in
Avatar of pagesheetal
pagesheetal

asked on

ORACLE SQL - to get the first_value and the last_value using OVER PARTITION BY

Hi Folks,

I have a table cnam_load which is Oracle table and the columns of the table are :-

mdn
action_type

I have to use the over partition by command to get the first value and the last value of the action_type and it should be grouped by mdn and count(*) > 1. I never used over partition by command and I am not sure how to build this query. I would appreciate your advice.

Thanks
Avatar of Sean Stuber
Sean Stuber

I'm assuming first and last are determined by order of the action type itself.

select * from
(select mdn, first_value(action_type) over (partition by mdn order by action_type) first_action,
last_value(action_type) over(partition by mdn over action_type) last_action,
count(*) over (partition by mdn) cnt
from cnam_load
) where cnt > 1
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial