Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 无效操作:在“或”附近出现语法错误;三角洲;_Sql_Amazon Redshift - Fatal编程技术网

Sql 无效操作:在“或”附近出现语法错误;三角洲;

Sql 无效操作:在“或”附近出现语法错误;三角洲;,sql,amazon-redshift,Sql,Amazon Redshift,我有红移脚本 下面是脚本的一部分代码 SELECT cog.organizationid, cog.clientid, t.MonthBilled, t.Month, t.Year, u.ClientCharges, cp.supervisorcontactid AS Principal, cc.fullname AS CSL, LAG(u.ClientCh

我有红移脚本

下面是脚本的一部分代码

    SELECT  cog.organizationid,
        cog.clientid,
        t.MonthBilled,
        t.Month,
        t.Year,
        u.ClientCharges,
        cp.supervisorcontactid AS Principal,
        cc.fullname AS CSL,

        LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) AS PreviosMonthCharges,

        CASE WHEN u.ClientCharges IS NULL THEN 0 ELSE u.ClientCharges END -
                                CASE WHEN LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL THEN 0
                                ELSE LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month)
                                END AS Delta,

        CASE WHEN (CASE WHEN u.ClientCharges IS NULL THEN 0 ELSE u.ClientCharges END - CASE WHEN LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL THEN 0
                                ELSE LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) END) > 0 THEN 'Gain'
             WHEN CASE WHEN u.ClientCharges IS NULL THEN 0 ELSE u.ClientCharges END - CASE WHEN LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL THEN 0
                                ELSE LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) END < 0 THEN 'Loss'
                                ELSE NULL END AS GainsLosses,
        CASE WHEN u.ClientCharges >=0 AND LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL AND t.MonthBilled <> '1/1/2015' THEN 'New' ELSE 'Existing' END AS ClientType,

        CASE WHEN u.ClientCharges IS NULL THEN 'InActive' ELSE 'Active' END AS ActiveStatus,

        CASE WHEN LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NOT NULL AND t.MonthBilled <> '1/1/2015' THEN 1 ELSE NULL END AS ActiveLastMonth,

        CASE WHEN u.ClientCharges IS NULL AND (LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) <> 0 AND LAG(u.ClientCharges,1,0) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NOT NULL) AND t.MonthBilled <> '1/1/2015' THEN 1 ELSE NULL END AS OneMonthChurn,

        u2.FeatureKeyCount,

        CASE WHEN u.ClientCharges IS NOT NULL AND u.ClientCharges > 0 THEN 1 ELSE 0 END AS OrgCounter
FROM    public.contacts_client_organization cog
选择cog.organizationid,
cog.clientid,
t、 蒙斯比勒,
t、 月,
t、 年,
u、 客户费用,
cp.supervisorcontactid作为负责人,
抄送全名为CSL,
滞后(u.ClientCharges,1,0)超过(按cog.clientid划分,按cog.clientid划分,t.Year,t.Month)作为上一个月的收费,
如果u.ClientCharges为空,则0,否则u.ClientCharges结束-
当滞后时间(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid的分割顺序,t.Year,t.Month)为空时,则为0
ELSE滞后(u.ClientCharges,1,0)超过(按cog.clientid划分,按cog.clientid划分,t年,t月)
以三角洲结束,
CASE WHEN(当u.ClientCharges为空时,则为0,否则u.ClientCharges结束-当滞后(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分的顺序)为空时,则为0
ELSE滞后(u.ClientCharges,1,0)超过(按cog.clientid划分,按cog.clientid划分,t年,t月)结束时>0,然后“增加”
当u.ClientCharges为空时,则为0,否则u.ClientCharges结束-当滞后(u.ClientCharges,1,0)超过(按cog.clientid划分,按cog.clientid排序,t.Year,t.Month)为空时,则为0
ELSE滞后(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid排序,t年,t月)结束时<0,则为“损失”
否则将以收益损失结束,
当u.ClientCharges>=0且滞后(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分)为空且t.MonthBilled为“1/1/2015”,然后“新建”或“现有”结束为ClientType,
如果u.ClientCharges为空,则“不活动”或“活动”结束为活动状态,
当滞后时间(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分的顺序)不为空且t.MonthBilled为'1/1/2015'时,则1否则为空,以ActiveLastMonth结束,
当u.ClientCharges为空且(滞后(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid划分,t.Year,t.Month)0且滞后(u.ClientCharges,1,0)超过(按cog.clientid按cog.clientid划分,t.Year,t.Month)且t.MonthBilled为'1/1/2015'时,则1以ONEMONHCHURN结束,
u2.FeatureKeyCount,
当u.ClientCharges不为NULL且u.ClientCharges>0时,则1或0结束为OrgCounter
来自public.contacts\u client\u organization cog
我在尝试运行时收到此错误消息

[42601][500310]Amazon无效操作:在“增量”位置或附近出现语法错误:747;java.lang.RuntimeException:com.amazon.support.exceptions.ErrorException:amazon无效操作:位于或接近“增量”位置的语法错误:747

但我不明白,怎么了

更新

这里是用有效延迟重写的部分,但我仍然有同样的问题

 SELECT  cog.organizationid,
        cog.clientid,
        t.MonthBilled,
        t.Month,
        t.Year,
        u.ClientCharges,
        cp.supervisorcontactid AS Principal,
        cc.fullname AS CSL,

        LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) AS PreviosMonthCharges,

        CASE WHEN u.ClientCharges IS NULL THEN 0 ELSE u.ClientCharges END -
                                CASE WHEN LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL THEN 0
                                ELSE LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month)
                                END AS Delta,

        CASE WHEN (CASE WHEN u.ClientCharges IS NULL THEN 0 ELSE u.ClientCharges END - CASE WHEN LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL THEN 0
                                ELSE LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) END) > 0 THEN 'Gain'
             WHEN CASE WHEN u.ClientCharges IS NULL THEN 0 ELSE u.ClientCharges END - CASE WHEN LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL THEN 0
                                ELSE LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) END < 0 THEN 'Loss'
                                ELSE NULL END AS GainsLosses,
        CASE WHEN u.ClientCharges >=0 AND LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NULL AND t.MonthBilled <> '1/1/2015' THEN 'New' ELSE 'Existing' END AS ClientType,

        CASE WHEN u.ClientCharges IS NULL THEN 'InActive' ELSE 'Active' END AS ActiveStatus,

        CASE WHEN LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NOT NULL AND t.MonthBilled <> '1/1/2015' THEN 1 ELSE NULL END AS ActiveLastMonth,

        CASE WHEN u.ClientCharges IS NULL AND (LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) <> 0 AND LAG(u.ClientCharges,1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid,t.Year,t.Month) IS NOT NULL) AND t.MonthBilled <> '1/1/2015' THEN 1 ELSE NULL END AS OneMonthChurn,

        u2.FeatureKeyCount,

        CASE WHEN u.ClientCharges IS NOT NULL AND u.ClientCharges > 0 THEN 1 ELSE 0 END AS OrgCounter
FROM    public.contacts_client_organization cog
选择cog.organizationid,
cog.clientid,
t、 蒙斯比勒,
t、 月,
t、 年,
u、 客户费用,
cp.supervisorcontactid作为负责人,
抄送全名为CSL,
滞后(u.ClientCharges,1)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分的顺序)作为上一个月的收费,
如果u.ClientCharges为空,则0,否则u.ClientCharges结束-
如果滞后时间(u.ClientCharges,1)超过(按cog.clientid划分,按cog.clientid划分,t.Year,t.Month)为空,则为0
ELSE滞后(u.ClientCharges,1)超过(按cog.clientid划分,按cog.clientid划分,t年,t月)
以三角洲结束,
CASE WHEN(当u.ClientCharges为空时,则为0,否则u.ClientCharges结束-当滞后(u.ClientCharges,1)超过(按cog.clientid划分,按cog.clientid排序,t.Year,t.Month)为空时,则为0
ELSE滞后(u.ClientCharges,1)超过(按cog.clientid划分,按cog.clientid划分,t年,t月)结束时>0,然后“增加”
当u.ClientCharges为空时,则为0,否则u.ClientCharges结束-当滞后(u.ClientCharges,1)超过(按cog.clientid划分,按cog.clientid排序,t.Year,t.Month)为空时,则为0
ELSE滞后(u.ClientCharges,1)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分的cog.clientid订单)结束时<0,则为“损失”
否则将以收益损失结束,
当u.ClientCharges>=0且滞后(u.ClientCharges,1)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分)为空且t.MonthBilled为“1/1/2015”,然后“新建”或“现有”结束为ClientType,
如果u.ClientCharges为空,则“不活动”或“活动”结束为活动状态,
当滞后(u.ClientCharges,1)超过(按cog.clientid按cog.clientid、t.Year、t.Month划分的顺序)不为空且t.MonthBilled为“2015年1月1日”时,则1否则为空,以ActiveLastMonth结束,
当u.ClientCharges为空且(滞后(u.ClientCharges,1)超过(按cog.clientid按cog.clientid划分,t.Year,t.Month)0且滞后(u.ClientCharges,1)超过(按cog.clientid按cog.clientid划分,t.Year,t.Month)且t.MonthBilled'1/1/2015'时,则1以一个月为空结束,
u2.FeatureKeyCount,
当u.ClientCharges不为NULL且u.ClientCharges>0时,则1或0结束为OrgCounter
来自public.contacts\u client\u organization cog

我不确定这是否是问题所在,但是
lag()
不接受红移中默认值的第三个参数

我将这样写:

    (COALESCE(u.ClientCharges, 0) -
     COALESCE(LAG(u.ClientCharges, 1) OVER (PARTITION BY cog.clientid ORDER BY cog.clientid, t.Year, t.Month), 0)
    ) as my_Delta,

DELTA
是一个,所以给它起一个不同的名字。

什么是COALESCE?我删除了3个参数,但仍然有这个错误它是
NVL()的ANSI/ISO标准版本