Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
title country market date

Title A Australia 54 01-02-18
Title A Australia 54 02-04-18
Title A Australia 54 29-09-18
Title A Australia 54 17-04-19
Title A Australia 54 15-04-20
Title A Australia 54 20-04-20
Title A Australia 54 10-05-22
Title A Australia 54 09-05-23
Title B Australia 54 29-09-18
Title B Germany 54 07-01-19
Let us consider three dates a,b,c and the three dates belongs to same title, country and market. Now my requirement is if the difference between two consecutive dates is less than 365 days then cycle should 1 else it should be incremented by one to next number. If the cycle is incremented then the reference date should be changed to the current date and the difference should be measured between next date and changed reference date and the process continues on till the current group i.e., dates belongs to same title, country and market are processed .

Then the process begins again from the beginning for the next set.

the output should as below: title country market date cycle

Title A Australia 54 01-02-18 1
Title A Australia 54 02-04-18 1
Title A Australia 54 29-09-18 1
Title A Australia 54 17-04-19 2
Title A Australia 54 15-04-20 2
Title A Australia 54 20-04-20 3
Title A Australia 54 10-05-22 4
Title A Australia 54 09-05-23 4
Title B Australia 54 29-09-18 1
Title B Germany 54 07-01-19 1

What I have tried:

tried with case statements and tried with multiple case and decode statements
Posted
Updated 14-Nov-18 19:46pm

1 solution

 
Share this answer
 
Comments
Member 14055051 15-Nov-18 1:49am    
can you give the query for that?
I tried I'm not getting exactly what I want.
OriginalGriff 15-Nov-18 2:07am    
Show us what you have first, and explain what it does that you didn't expect, or doesn't do that you did.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900