Home » SQL & PL/SQL » SQL & PL/SQL » compare prev records with current
compare prev records with current [message #594551] Thu, 29 August 2013 18:30 Go to next message
saikumar
Messages: 2
Registered: February 2008
Junior Member
Hi
I am trying to set the min date if there is no gap between dates.compare previous date2 value with current date1,if they are same then my new date will be min(date1).

source  data
			
date1	         id	date2	            new_date
1/2/2011	123	4/2/2011	
4/2/2011	123	7/2/2011	
7/2/2011	123	10/2/2011	
10/2/2011	123	1/2/2012	
1/2/2012	123	4/2/2012	
4/2/2012	123	7/2/2012	
12/17/2012	123	3/17/2013	
3/17/2013	123	6/17/2013	

and I am expecting the out put like this

date1	        id	 date2	        new_date
1/2/2011	123	4/2/2011	1/2/2011
4/2/2011	123	7/2/2011	1/2/2011
7/2/2011	123	10/2/2011	1/2/2011
10/2/2011	123	1/2/2012	1/2/2011
1/2/2012	123	4/2/2012	1/2/2011
4/2/2012	123	7/2/2012	1/2/2011
12/17/2012	123	3/17/2013	12/17/2012
3/17/2013	123	6/17/2013	12/17/2012


any idea how to achive this with SQL

*BlackSwan added {code} tags. Please do so yourself in the future.

[Updated on: Thu, 29 August 2013 19:00] by Moderator

Report message to a moderator

Re: compare prev records with current [message #594552 is a reply to message #594551] Thu, 29 August 2013 18:33 Go to previous messageGo to next message
BlackSwan
Messages: 21951
Registered: January 2009
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: compare prev records with current [message #594553 is a reply to message #594552] Thu, 29 August 2013 21:02 Go to previous messageGo to next message
saikumar
Messages: 2
Registered: February 2008
Junior Member
thanks BlackSwan for adding tags
Re: compare prev records with current [message #594558 is a reply to message #594551] Fri, 30 August 2013 00:36 Go to previous message
Michel Cadot
Messages: 57613
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Welcome to the forum.

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Regards
Michel
Previous Topic: synonym and permission
Next Topic: PLS-00497: cannot mix between single row and multi-row (BULK) in INTO list
Goto Forum:
  


Current Time: Sun Apr 20 14:22:55 CDT 2014

Total time taken to generate the page: 0.08397 seconds