SQL 编译错误:语法错误第 5 行位于位置 157 意外的“<EOF>”

arr*_*arr 0 sql syntax-error snowflake-cloud-data-platform

这里可能出了什么问题?

create or replace temp table Whse_Role_Spend as
with 
Warehouse_Spend as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name from 
"SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name),
Role_Spend as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name, role_name from 
"SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name, role_name),
Credits_Used as (select sum(Credits_used) Credits_Used, warehouse_name from 
"SNOWFLAKE"."ACCOUNT_USAGE"."WAREHOUSE_METERING_HISTORY" group by warehouse_name)
Run Code Online (Sandbox Code Playgroud)

Gre*_*lik 6

它给出了 EOF 错误,因为存在没有 CTE 查询的 CTE 定义。编译器在找到 CTE 查询之前就到达了语句末尾,因此它返回 EOF 错误。

CTE 定义还需要在表表达式上定义列。您需要连接这些表,但您希望它们出现在 CTE 查询中(最后)。这应该可以帮助您解决 EOF 问题,并接近您可以按照您想要的方式完成语句的位置。

create or replace temp table Whse_Role_Spend as
with 
    Warehouse_Spend(total_elapsed, warehouse_name) as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name from 
        "SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name),
    Role_Spend (Total_Elapsed, warehouse_name, role_name) as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name, role_name from 
        "SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name, role_name),
    -- Add column definitions on the next table expression similar to the ones above.
    Credits_Used as (select sum(Credits_used) Credits_Used, warehouse_name from 
        "SNOWFLAKE"."ACCOUNT_USAGE"."WAREHOUSE_METERING_HISTORY" group by warehouse_name)
select s.total_elapsed, 
       s.warehouse_name
from WAREHOUSE_SPEND S, ROLE_SPEND R; -- Join the CTE tables as you need them
Run Code Online (Sandbox Code Playgroud)