We help IT Professionals succeed at work.

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

pagesheetal
pagesheetal asked
on
4,503 Views
Last Modified: 2013-12-19
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
Comment
Watch Question

Sean StuberDatabase Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012

Commented:
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
Database Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.