[英]AWS Athena (Presto) - multiple WITH statements
Is there a way to use multiple WITH statements in Athena/Presto?有没有办法在 Athena/Presto 中使用多个 WITH 语句?
WITH "revenue" AS (
SELECT
"cik",
"accession",
"year",
"quarter",
"form type" as "form_type",
CAST("value" AS bigint) as "revenue",
CAST("value" - lag("value") over (partition by "cik") AS bigint) as "increment",
ROUND("value" / lag("value") over (partition by "cik"),2) as "ratio"
FROM "gaap"
WHERE
"form type" IN ('10-K')
AND "rep" = 'revenue'
ORDER BY
"cik", "year", "quarter", "fs" desc
)
WITH "cik_with_continuous_growth" AS (
SELECT "cik"
FROM "revenue"
WHERE
"ratio" >= 1.5
AND "year" >= 2016
GROUP BY "cik"
HAVING COUNT("ratio") >= 3
ORDER BY "cik"
)
SELECT * FROM "cik_with_continuous_growth";
Only one sql statement is allowed.只允许使用一条 sql 语句。 Got: WITH "revenue" AS ( SELECT "cik", "accession", "year", "quarter", "form type" as "form_type", CAST("value" AS bigint) as "revenue", CAST("value" - lag("value") over (partition by "cik") AS bigint) as "increment", ROUND("value" / lag("value") over (partition by "cik"),2) as "ratio" FROM "gaap" WHERE "form type" IN ('10-K') AND "rep" = 'revenue' ORDER BY "cik", "year", "quarter", "fs" desc ) WITH "cik_with_continuous_growth" AS ( SELECT "cik" FROM "revenue" WHERE "ratio" >= 1.5 AND "year" >= 2016 GROUP BY "cik" HAVING COUNT("ratio") >= 3 ORDER BY "cik" ) SELECT * FROM "cik_with_continuous_growth";得到: WITH "revenue" AS ( SELECT "cik", "accession", "year", "quarter", "form type" as "form_type", CAST("value" AS bigint) as "revenue", CAST(" value" - lag("value") over (partition by "cik") AS bigint) 作为 "increment", ROUND("value" / lag("value") over (partition by "cik"),2) as " ratio" FROM "gaap" WHERE "form type" IN ('10-K') AND "rep" = 'revenue' ORDER BY "cik", "year", "quarter", "fs" desc ) WITH "cik_with_continuous_growth" AS(SELECT“cik”来自“收入”,其中“比率”>= 1.5 和“年”>= 2016 分组按“cik”有计数(“比率”)>= 3 按“cik”排序)Z63225F19FCCB18E7C709F1FA111BC7 "; #WHERE "revenue"."cik" = "cik_with_continuous_growth"."cik"; #WHERE "收入"."cik" = "cik_with_continuous_growth"."cik";
WITH "revenue" AS (,
SELECT "cik", "accession", year, quarter.
"form type" as "form_type",
CAST("value" AS bigint) as "revenue",
CAST("value" - lag("value") over (partition by "cik") AS bigint) as "increment",
ROUND("value" / lag("value") over (partition by "cik"),2) as "ratio"
FROM "gaap"
WHERE "form type" IN ('10-K') AND
"rep" = 'revenue' AND
ORDER BY "cik", "year", "quarter", "fs" desc
),
"cik_with_continuous_growth" AS (
SELECT "cik"
FROM "revenue"
WHERE "ratio" >= 1.5 AND
"year" >= 2016
GROUP BY "cik"
HAVING COUNT("ratio") >= 3
ORDER BY "cik"
)
SELECT * FROM "cik_with_continuous_growth";
have you tried with a as ( ), b as () select * from a,b
?你试过with a as ( ), b as () select * from a,b
吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.