Have a below table,
customer ID, code, start_date, end_date
124343, DCW, 2015-07-06, 2016-08-03
235432, ABC, 2015-04-26, NULL
235432, ABC, 2015-04-26, 2015-06-20
3242342, ABC, 2015-08-02, 2015-07-28
2332434, DCW, 2015-02-09, 2015-06-23
2332434, DCW, 2015-06-23, NULL
What to use recurcive query to get output for unique code for each customerID,
1. when customer ID has more than 1 record in table with value in end_date and null in end_date then only records with null end_date.
2. when customer ID has more than 1 record with start_date, end_date and start_date equal to end_date for the first record then only record with null end_date or future date than today's date.
3. end_date more than today's date
Required Output
customer ID, code, start_date, end_date
124343, DCW, 2015-07-06, 2016-08-03
235432, ABC, 2015-04-26, null
3242342, ABC, 2015-08-02, 2015-07-28
2332434, DCW, 2015-06-23, null