Subject: Take the data from table and rotate the member on every 7th day or starting day of the week and continue for whole week continue till the date range

From: nikhil raj <[email-masked]>
Date: Sun, 26 Feb 2023 02:05:22 +0530

Hi All,

Need help in rotation of data in *Postgres*.

There is a table called crew_details

 <https://i.stack.imgur.com/cTarQ.png>

There is a requirement to rotate the crew members for in weekly or on the
every 7th day and continue for rest 6days the same order of for the given
date range un till it reach end date . and the expected output should be
like this below

 <https://i.stack.imgur.com/hjasI.png>

Please can any one help me in in the rotation in *postgres SQL*

---

From: nikhil raj <[email-masked]>
Date: Sun, 26 Feb 2023 02:34:02 +0530

Hi All,

---

From: Steve Midgley <[email-masked]>
Date: Sat, 25 Feb 2023 13:56:27 -0800

> Please can any one help me in in the rotation in *postgres SQL*

Thanks for posting the table and output. I'm not totally clear on the
business requirements here but it seems like you have a crew rotation
sequence that is, in this case modulus 5?

I'm not sure I've got the SQL skills to easily make this in a single query
(but surely others here can). But just to clarify the business rules for
such a SQL wizard, I would think the solution involves some kind of hidden
variable (new column, aggregation, built in function?) where the number 1
team member's crew position number is incremented by 1 mod 5 for each new
shift date. Whenever that tracking counter becomes 1 again, convert their
actual shift order number to 5, and subtract 1 from every other crew
members' crew position number. Does that sound like the correct business
rule for the process you're trying to create?

Steve

---

From: nikhil raj <[email-masked]>
Date: Tue, 28 Feb 2023 01:15:46 +0530

Hi Steve,

Yes, that is correct.