Please see attached excel file for sample data.
I want to mark records from the same customer as Index / ReIndex (in the service_type column) based on the following rule:
Flag all records with svc_order =1 as 'Index' in Service_type column.
If customer_id is same
and DateDiff in days (svc_start_date for previous record where svc_order = svc_order-1, same customer_id) <=30
Then Flag it as Re-Index.
Attached sample data in excel file.
service_Type column will be initially null and updated as mentioned in the above logic.
How can I accomplish this using sql?