Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWjSt-0003tT-HQ for pgsql-sql@arkaria.postgresql.org; Mon, 27 Feb 2023 19:47:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pWjSs-0007UI-7W for pgsql-sql@arkaria.postgresql.org; Mon, 27 Feb 2023 19:47:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWjSr-0007U9-Rq for pgsql-sql@lists.postgresql.org; Mon, 27 Feb 2023 19:47:13 +0000 Received: from mail-vs1-xe2a.google.com ([2607:f8b0:4864:20::e2a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pWjSm-0004Qx-80 for pgsql-sql@postgresql.org; Mon, 27 Feb 2023 19:47:13 +0000 Received: by mail-vs1-xe2a.google.com with SMTP id m10so13053794vso.4 for ; Mon, 27 Feb 2023 11:47:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RorCwGWe8q0eA9SFBKVjV2uDrh2pgESl3DW2/noIQf8=; b=iJPyGLlAcLUWGR+ImX31K3bAJHtg4NmNHmJeomU3omB94WuEyrY85sfHYbA+kuQCLR ioDbVhRZ4qTgGcsXTqUW+k+s9dJHhgQZHuow/ik05lD0nOnTq4+04lmVsXWFWXf1gEMk 53b75c8aT3w8kBozJukb/AndmyaHpykdV7ApXlFQ6Zur+0Ta3/FKbfmu0lazIAms4iA3 W80UMHJDZOramQ4iKv0oNehz5h/dR60NDnXXL3d6JCsbJGsuzrDpatuZUHiWLmkWGUtM wkAmcaPP8aFxzLqUG5JfT7lau5NXvOmBVES4EguL9vEkOxulpAd3Dxr5Px9v67rSIYOI hCLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RorCwGWe8q0eA9SFBKVjV2uDrh2pgESl3DW2/noIQf8=; b=KqyRayvxSRUCfcjrzVMgnIo+hEYIlZScGnVdB0767pg99EaMSH1zgnmxSF3AczQVDs vQfX+zf054e5UHLh2eChJ+ukISmDtORCztV0FK4TPvY1RtYVms3y4ooRKXV/GNoSXLXo +8wK/EpCKCcB5lhX4yTUsaniKSt43y9pohcqChfmh/NOw0Qg94TCgNAA9LHF6UpKvHZo 4Kvnjq+0Mjev6JGGD7xAgWnbk55IRXizP6JUfhRFrtiClsw4iK9WwkUKE/4Qd47pWl03 7sTkb2hYlxSyFEFXRjzgxH7WdB+lnIXnOQ4CtvohjTYoGfmHkwf3kgSIXQc5HxDfRe0C PXRQ== X-Gm-Message-State: AO0yUKVStftff+pBUaCviE3kP4vHWeoh4vlRVNO6PA00nnEjx69sDnaM ur/+auh4mY91OGPOBZjEx07WOzoat7pcOcm+pEg= X-Google-Smtp-Source: AK7set9J4+kUK1K2P1bGMsWi/frLglrQ5+19dBzR7SJYHI1DAVK9I7N2bQCmAMcjNBEjxFnjkPndWCTk72KcCqtgyOQ= X-Received: by 2002:a05:6122:1205:b0:401:1c83:fba3 with SMTP id v5-20020a056122120500b004011c83fba3mr7756283vkc.3.1677527226572; Mon, 27 Feb 2023 11:47:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: nikhil raj Date: Tue, 28 Feb 2023 01:15:46 +0530 Message-ID: Subject: Re: 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 To: Steve Midgley Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary="00000000000070e3e605f5b3becf" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000070e3e605f5b3becf Content-Type: text/plain; charset="UTF-8" Hi Steve, Yes, that is correct. On Sun, Feb 26, 2023 at 3:26 AM Steve Midgley wrote: > > > On Sat, Feb 25, 2023 at 12:37 PM nikhil raj > wrote: > >> >> Hi All, >> >> Need help in rotation of data in *Postgres*. >> >> There is a table called crew_details >> >> [image: enter image description here] >> >> >> 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 >> >> [image: >] >> >> 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 > --00000000000070e3e605f5b3becf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Steve,

Yes, that is corre= ct.=C2=A0=C2=A0

On Sun, Feb 26, 2023 at 3:26 AM Steve Midgley <= science@misuse.org> wrote:
=


On Sat, Feb 25, 2023 at 12:37 PM nikhil raj <nikhilraj474@gmail.com= > wrote:
=

Hi All,

Need help in rotation of data in=C2=A0Postgres.

There is a = table called crew_details

3D"enter<= /p>

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 t= he given date range un till it reach end date . and the expected output sho= uld be like this below

3D">"

Please can any one help me= in in the rotation in=C2=A0p= ostgres 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 su= ch a SQL wizard, I would think the solution involves some kind of hidden va= riable (new column, aggregation, built in function?) where the number 1 tea= m 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 a= ctual 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=
--00000000000070e3e605f5b3becf--