Home » SQL & PL/SQL » SQL & PL/SQL » get row above stated on (10g)
get row above stated on [message #390762] Mon, 09 March 2009 11:31 Go to next message
reachmexyz
Messages: 8
Registered: February 2009
Location: New Jersey
Junior Member
hello all

I have a table with fields like

col1 col2 col3
2007 N 3
2007 Y 2
2008 N 1

In mycase i have to check for the row with col2='Y' and then extract the record above it.
The output should be like
2007 N 3 (row above with col2='Y').
How can i do this.Can i do this using any analytical Functions.
And also i have to do this in SQL. Not in PL/SQL
Re: get row above stated on [message #390763 is a reply to message #390762] Mon, 09 March 2009 11:32 Go to previous messageGo to next message
BlackSwan
Messages: 25032
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
So we can help you & please be consistent & correct in your postings.

Post DDL for tables.
Post DML for test data.

Post expected/desired results.

Re: get row above stated on [message #390764 is a reply to message #390762] Mon, 09 March 2009 11:33 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Quote:
Can i do this using any analytical Functions
Yes you can. Look at the LAG function in the documentation
Re: get row above stated on [message #390765 is a reply to message #390762] Mon, 09 March 2009 11:34 Go to previous messageGo to next message
ashoka_bl
Messages: 398
Registered: November 2006
Location: Bangalore
Senior Member

Quote:

How can i do this.Can i do this using any analytical Functions.


Yes you can do with analytical functions.

Regards,
Ashoka BL
Re: get row above stated on [message #390767 is a reply to message #390762] Mon, 09 March 2009 11:37 Go to previous message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Of course you have to know how you define "above" in SQL.

Regards
Michel
Previous Topic: Query checker
Next Topic: Date difference from Prior and Current rows (merged)
Goto Forum:
  


Current Time: Fri Dec 02 12:42:03 CST 2016

Total time taken to generate the page: 0.14519 seconds