Home > Software engineering >  TSQL, counting coherent days of holiday
TSQL, counting coherent days of holiday

Time:01-29

I hope someone can help me on this one. :-)

I wish to count coherent periods of holiday to see if anyone had coherent holiday more than three days in a row. In other words it is not enough to count the number of days overall. The days have to be coherent. In the example of my data below I have illustrated three people with each their own days of holiday. Person 1234 has two periods of two days of holiday in a row, so this person has no periods above three days since there is a day in between two periods (the 3rd). Person 1235 and 1236 each have one period above three days. Time of day in the timestamps has no relevance, so data can be formatted as just date.

What I have:

ID Start
1234 2022-01-01 00:00:00
1234 2022-01-02 00:00:00
1234 2022-01-04 06:50:00
1234 2022-01-05 06:50:00
1235 2022-01-04 06:50:00
1235 2022-01-05 06:50:00
1235 2022-01-06 00:00:00
1236 2022-01-01 00:00:00
1236 2022-01-02 00:00:00
1236 2022-01-03 06:50:00
1236 2022-01-04 06:50:00
1236 2022-01-05 06:50:00
1236 2022-01-08 00:00:00

What I hope to get:

ID N holidays > 3 days
1234 0
1235 1
1236 1

Anyways, any help will be appreciated!

Kind regards,

Jacob

CodePudding user response:

@Andy3B: I understand your confusion and apologize, I just used fictional data to simplify the case. I have now corrected it, since I shouldn't use the end column.

CodePudding user response:

@Rigerta: you are quite right, my apologies. I used fictional data, which I have corrected now. I should only use the Start day for this.

  •  Tags:  
  • Related