运行以下查询时出现资源超出错误,如何重写此查询以避免该错误?
SELECT
XXX_lnaourj_ID,
XXX_DR_Tma_LC,
XXX_CR_Tma_LC,
XXX_Amount_LC,
XXX_TLAffect_LC,
XXX_Entry_Desc,
XXX_DocType,
XXX_TCode,
XXX_Company,
XXX_Posted_By,
XXX_Parked_By,
XXX_Accounting_Date,
XXX_Creation_Date
FROM
[acl_data.XXX_JE_All_Formatted]
WHERE
XXX_lnaourj_ID IN (
SELECT
XXX_lnaourj_ID
FROM
[acl_data.XXX_JE_All_Formatted]
WHERE
XXX_Creation_Date - XXX_Accounting_Date > 30 )
ORDER BY
XXX_lnaourj_ID ASC;
答案 0 :(得分:1)
由于您在主semijin中使用相同的表,因此可以简化查询以避免这种自我半连接(并避免两次执行表扫描)。取决于结果的大小,删除ORDER BY也可能有所帮助:
SELECT
XXX_lnaourj_ID,
XXX_DR_Tma_LC,
XXX_CR_Tma_LC,
XXX_Amount_LC,
XXX_TLAffect_LC,
XXX_Entry_Desc,
XXX_DocType,
XXX_TCode,
XXX_Company,
XXX_Posted_By,
XXX_Parked_By,
XXX_Accounting_Date,
XXX_Creation_Date
FROM
[acl_data.XXX_JE_All_Formatted]
WHERE
XXX_Creation_Date - XXX_Accounting_Date > 30
答案 1 :(得分:1)
尝试通过添加" group by"来欺骗Bigquery。在子查询中。它有时对我有帮助。
SELECT
XXX_lnaourj_ID,
XXX_DR_Tma_LC,
XXX_CR_Tma_LC,
XXX_Amount_LC,
XXX_TLAffect_LC,
XXX_Entry_Desc,
XXX_DocType,
XXX_TCode,
XXX_Company,
XXX_Posted_By,
XXX_Parked_By,
XXX_Accounting_Date,
XXX_Creation_Date
FROM
[acl_data.XXX_JE_All_Formatted]
WHERE
XXX_lnaourj_ID IN (
SELECT
XXX_lnaourj_ID
FROM
[acl_data.XXX_JE_All_Formatted]
WHERE
XXX_Creation_Date - XXX_Accounting_Date > 30
GROUP BY
XXX_lnaourj_ID )
ORDER BY
XXX_lnaourj_ID ASC
如果这不起作用...... Bigquery不是加入的粉丝...... 试试这个:
Select *
from
(
Select *,
max(XXX_Creation_Date - XXX_Accounting_Date) over(partition by XXX_lnaourj_ID) as maxdatediff
From [acl_data.XXX_JE_All_Formatted]
)
where maxdatediff>30