У меня есть скрипт MSSQL Server, который мне нужно переписать в Redshift
Вот оригинальная часть из сценария
SELECT cog.OrganizationId,
cog.ClientId,
REPLACE(REPLACE(AM, 'IAM: ', 'IMP: '),'AM: ', '') AS AM,
u.ProcedureCodeString,
t.MonthBilled,
t.Month,
t.Year,
u.ClientCharges,
LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) AS PreviosMonthCharges,
LAG(u.ClientCharges,2,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) AS TwoMonthsAgoCharges,
LAG(u.ClientCharges,3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) AS ThreeMonthsAgoCharges,
LAG(u.ClientCharges,4,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) AS FourMonthsAgoCharges,
LAG(t.MonthBilled,3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) AS ThreeMonthsAgoDate,
DATEDIFF(d,CASE WHEN LAG(CONVERT(datetime,t.MonthBilled),3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) = 0 THEN NULL ELSE LAG(CONVERT(datetime,t.MonthBilled),3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) END,CONVERT(datetime,t.MonthBilled) ) AS DateDifCheck,
b.FirstMonth,
b.FirstFeature,
CASE WHEN u.ClientCharges > 0
AND LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) > 0
AND LAG(u.ClientCharges,2,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) > 0
AND LAG(u.ClientCharges,3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) > 0
AND LAG(u.ClientCharges,4,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) = 0
AND LAG(t.MonthBilled,3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) > b.FirstMonth
AND DATEDIFF(d,CASE WHEN LAG(CONVERT(datetime,t.MonthBilled),3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) = 0 THEN NULL ELSE LAG(CONVERT(datetime,t.MonthBilled),3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) END,CONVERT(datetime,t.MonthBilled) ) < 95
AND DATEDIFF(d,CASE WHEN LAG(CONVERT(datetime,t.MonthBilled),3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) = 0 THEN NULL ELSE LAG(CONVERT(datetime,t.MonthBilled),3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.ClientId,t.Year,t.Month) END,CONVERT(datetime,t.MonthBilled) ) > 88
AND u.ProcedureCodeString <> b.FirstFeature
THEN 1 ELSE 0 END AS CommissionReportFlag
FROM dbo.Contacts_ClientOrganization cog WITH(NOLOCK)
А вот как я это переписал
SELECT cog.organizationid,
cog.clientid,
REPLACE(REPLACE(AM, 'IAM: ', 'IMP: '),'AM: ', '') AS AM,
u.ProcedureCodeString,
t.MonthBilled,
t.Month,
t.Year,
u.ClientCharges,
LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) AS PreviosMonthCharges,
LAG(u.ClientCharges,2,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) AS TwoMonthsAgoCharges,
LAG(u.ClientCharges,3,0) OVER (PARTITION BY cog.ClientId, u.ProcedureCodeString ORDER BY cog.сlientid,t.Year,t.Month) AS ThreeMonthsAgoCharges,
LAG(u.ClientCharges,4,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.сlientid,t.Year,t.Month) AS FourMonthsAgoCharges,
LAG(t.MonthBilled,3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) AS ThreeMonthsAgoDate,
DATEDIFF(d,CASE WHEN LAG(CONVERT(TIMESTAMP,t.MonthBilled),3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) = 0 THEN NULL ELSE LAG(CONVERT(TIMESTAMP,t.MonthBilled),3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) END,CONVERT(TIMESTAMP,t.MonthBilled) ) AS DateDifCheck,
b.FirstMonth,
b.FirstFeature,
CASE WHEN u.ClientCharges > 0
AND LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) > 0
AND LAG(u.ClientCharges,2,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) > 0
AND LAG(u.ClientCharges,3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) > 0
AND LAG(u.ClientCharges,4,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) = 0
AND LAG(t.MonthBilled,3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) > b.FirstMonth
AND DATEDIFF(d,CASE WHEN LAG(CONVERT(TIMESTAMP,t.MonthBilled),3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) = 0 THEN NULL ELSE LAG(CONVERT(TIMESTAMP,t.MonthBilled),3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) END,CONVERT(TIMESTAMP,t.MonthBilled) ) < 95
AND DATEDIFF(d,CASE WHEN LAG(CONVERT(TIMESTAMP,t.MonthBilled),3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) = 0 THEN NULL ELSE LAG(CONVERT(TIMESTAMP,t.MonthBilled),3,0) OVER (PARTITION BY cog.clientid, u.ProcedureCodeString ORDER BY cog.clientid,t.Year,t.Month) END,CONVERT(TIMESTAMP,t.MonthBilled) ) > 88
AND u.ProcedureCodeString <> b.FirstFeature
THEN 1 ELSE 0 END AS CommissionReportFlag
FROM public.contacts_client_organization cog
Но теперь я получаю эту ошибку
[42601] [500310] Amazon Недопустимая операция: параметр по умолчанию не поддерживается для задержки оконной функции; java.lang.RuntimeException: com.amazon.support.exceptions.ErrorException: Amazon Недопустимая операция: параметр по умолчанию не поддерживается для задержки оконной функции;
Как я могу это исправить?