Re: Code does Not Read in FY 2025 Data - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Code does Not Read in FY 2025 Data
Date
Msg-id 82ff4dac-d8b0-4b8b-aa88-e5d74f624a4d@aklaver.com
Whole thread Raw
In response to Re: Code does Not Read in FY 2025 Data  (Anthony Apollis <anthony.apollis@gmail.com>)
List pgsql-general
On 7/16/24 07:59, Anthony Apollis wrote:
> I am using Postgres and SQL Server.

Does the query 'fail' on both platforms?

> Can you test the data pls.

Don't know what I am supposed to see?

You will need to provide an explanation of what you want the query to 
return vs what is currently being returned. Probably easiest to provide 
a sample of data and what you expect the query to return from that data. 
Do this inline in your post.

FYI, further investigation of the zipped data shows the 2025 data has FY 
values of NULL which would fail "FY" IS NOT NULL.

> 
> On Tue, 16 Jul 2024 at 16:45, Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 7/16/24 05:53, Anthony Apollis wrote:
>      >  1. The problem is the code below reads only data up until 2024,
>      >     although the table has been updated with latest data that
>     contains
>      >     2025, for some odd reason it is not pulling in or showing
>     data when
>      >     filtering for 2025 or even 2024 and later, which should
>     contain all
>      >     the latest data.
>      >  2.   SQL: "SET DATEFIRST 7;-- Holding Period Query
> 
>     I don't recognize SET DATEFIRST 7 as Postgres command.
> 
>     What database are you running this on?
> 
>     Have not gone through the below fully, but this:
> 
>     "FY" IS NOT NULL AND "FY" >= 'FY24'
> 
>     and this
> 
>     WEEK_NUMBER."Date" < CURRENT_DATE
> 
>     would seem to be at odds if you want to reach into 2025.
> 
>      >
>      >     SELECT
>      >
>      >  3.
>      >
>      >     -- Holding Period Query
>      >     SELECT
>      >          WEEK_NUMBER."Week Number",
>      >          WM_GH."Calendar day",
>      >          WM_GH."Month/Week",
>      >          WM_GH."Day name",
>      >          WM_GH."Company",
>      >          WM_GH."Material Code",
>      >          WM_GH."Metric",
>      >          WM_GH."Metric Value"
>      >     FROM
>      >          (
>      >              SELECT
>      >                  "Calendar day",
>      >                  "Month/Week",
>      >                  "Day name",
>      >                  "Company",
>      >                  "Material Code",
>      >                  "Metric",
>      >                  "Metric Value"
>      >              FROM
>      >
>      >   
>       "Prod"."IMETA_Weekly_Metrics_in_Focus_Global_Stock_View_SAP_BW" AS
>     WM_GH
>      >              WHERE
>      >                  WM_GH."Metric Focus" LIKE 'Weekly'
>      >                  AND WM_GH."Calendar day" <= (
>      >                      SELECT MAX(WEEK_NUMBER."Date") AS "MAX DATE"
>      >                      FROM (
>      >                          SELECT
>      >                              "Date",
>      >                              "Week number",
>      >                              COUNT("Date") OVER (PARTITION BY "Week
>      >     number" ORDER BY "Week number") AS "Number of days",
>      >                              COUNT("Date") OVER (PARTITION BY "Week
>      >     number" ORDER BY "Date") AS "Day number in weeks"
>      >                          FROM (
>      >                              SELECT DISTINCT
>      >                                  "Date",
>      >                                  EXTRACT(WEEK FROM
>     WEEK_NUMBER."Date")
>      >     AS "Week number"
>      >                              FROM
>      >
>      >     "dbo"."IMETA_Calendar_Days_Data_Table_Copy10" AS WEEK_NUMBER
>      >                              WHERE
>      >                                  "FY" IS NOT NULL AND "FY" >= 'FY24'
>      >                          ) AS W_MAX
>      >                      ) AS WEEK_NUMBER
>      >                      WHERE
>      >                          WEEK_NUMBER."Date" < CURRENT_DATE
>      >                          AND "Number of days" = "Day number in weeks"
>      >                  )
>      >          ) AS WM_GH
>      >     LEFT OUTER JOIN
>      >          (
>      >              SELECT
>      >                  *
>      >              FROM (
>      >                  SELECT
>      >                      "Date",
>      >                      "Week number",
>      >                      COUNT("Date") OVER (PARTITION BY "Week number"
>      >     ORDER BY "Week number") AS "Number of days",
>      >                      COUNT("Date") OVER (PARTITION BY "Week number"
>      >     ORDER BY "Date") AS "Day number in weeks"
>      >                  FROM (
>      >                      SELECT DISTINCT
>      >                          "Date",
>      >                          EXTRACT(WEEK FROM WEEK_NUMBER."Date") AS
>     "Week
>      >     number"
>      >                      FROM
>      >                         
>     "dbo"."IMETA_Calendar_Days_Data_Table_Copy10"
>      >     AS WEEK_NUMBER
>      >                  ) AS W_MAX
>      >              ) AS WEEK_NUMBER
>      >              WHERE
>      >                  WEEK_NUMBER."Date" < CURRENT_DATE
>      >          ) AS WEEK_NUMBER
>      >     ON
>      >          WM_GH."Calendar day" = WEEK_NUMBER."Date"
>      >     ORDER BY
>      >          WM_GH."Calendar day" DESC;
>      >
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com




pgsql-general by date:

Previous
From: Ray O'Donnell
Date:
Subject: Re: Code does Not Read in FY 2025 Data
Next
From: Adrian Klaver
Date:
Subject: Re: Code does Not Read in FY 2025 Data