BigQuery:[CTE Table 名称] 缺少数据集,而请求中未设置默认数据集
BigQuery: [CTE Table name] missing dataset while no default dataset is set in the request
我原来的 table 有:
(1) acceptance_rate - 字符串,百分比
(2) host_is_superhost - 布尔值
我想将 (1) acceptance_rate 转换为没有 % 的整数,所以我创建了一个 CTE,如下所示:
WITH acceptance_rate_cte AS
(SELECT
CAST(REPLACE(acceptance_rate,'%',"") AS int) AS new_acceptance_rate,
host_is_superhost AS new_superhost
FROM table1
WHERE acceptance_rate NOT IN ("N/A","0%")
ORDER BY new_acceptance_rate DESC)
SELECT new_acceptance_rate, new_superhost
FROM acceptance_rate_cte;
新 CTE table 看起来像:
new_acceptance_rate | new_superhost
100 |真
90 |真
95 |错误的
...
下一步,我想创建一个 table 以将所有 new_acceptance_rate 分组到 20 个桶中,然后计算这些桶中有多少 true 或 false。所以我这样做了:
SELECT CASE WHEN new_acceptance_rate >0 AND new_acceptance_rate <= 20 then '1-20'
WHEN new_acceptance_rate >20 AND new_acceptance_rate <=40 then '21-40'
WHEN new_acceptance_rate >40 AND new_acceptance_rate<=60 THEN '41-60'
WHEN new_acceptance_rate >60 AND new_acceptance_rate <=80 THEN '61-80'
ELSE 'Above 80'
END acceptance_range,
new_superhost,
count(*) as superhost_count
FROM acceptance_rate_cte
我对结果的期望是这样的:
acceptance_range | new_superhost | superhost_count
1-20 |真 | 15
1-20 |假 | 25
...
但是我收到如下错误消息:
Error running query Table name "acceptance_rate_cte" missing dataset
while no default dataset is set in the request.
我 运行 你上面的查询和一些示例数据似乎大部分是正确的。
with acceptance_rate_cte AS
( SELECT
CAST(REPLACE(acceptance_rate,'%',"") AS int) AS new_acceptance_rate,
host_is_superhost AS new_superhost
FROM table1
WHERE acceptance_rate NOT IN ("N/A","0%")
ORDER BY new_acceptance_rate DESC
)
SELECT CASE WHEN new_acceptance_rate >0 AND new_acceptance_rate <= 20 then '1-20'
WHEN new_acceptance_rate >20 AND new_acceptance_rate <=40 then '21-40'
WHEN new_acceptance_rate >40 AND new_acceptance_rate<=60 THEN '41-60'
WHEN new_acceptance_rate >60 AND new_acceptance_rate <=80 THEN '61-80'
ELSE 'Above 80'
END acceptance_range,
new_superhost,
count(*) as superhost_count
FROM acceptance_rate_cte
GROUP BY acceptance_range, new_superhost;
我确实必须添加一个分组依据才能使其正确执行。根据您的错误,尽管我猜测您没有 运行 在同一会话中同时使用 CTE 和查询。当你同时执行 运行 时。
我原来的 table 有: (1) acceptance_rate - 字符串,百分比 (2) host_is_superhost - 布尔值
我想将 (1) acceptance_rate 转换为没有 % 的整数,所以我创建了一个 CTE,如下所示:
WITH acceptance_rate_cte AS
(SELECT
CAST(REPLACE(acceptance_rate,'%',"") AS int) AS new_acceptance_rate,
host_is_superhost AS new_superhost
FROM table1
WHERE acceptance_rate NOT IN ("N/A","0%")
ORDER BY new_acceptance_rate DESC)
SELECT new_acceptance_rate, new_superhost
FROM acceptance_rate_cte;
新 CTE table 看起来像:
new_acceptance_rate | new_superhost
100 |真
90 |真
95 |错误的 ...
下一步,我想创建一个 table 以将所有 new_acceptance_rate 分组到 20 个桶中,然后计算这些桶中有多少 true 或 false。所以我这样做了:
SELECT CASE WHEN new_acceptance_rate >0 AND new_acceptance_rate <= 20 then '1-20'
WHEN new_acceptance_rate >20 AND new_acceptance_rate <=40 then '21-40'
WHEN new_acceptance_rate >40 AND new_acceptance_rate<=60 THEN '41-60'
WHEN new_acceptance_rate >60 AND new_acceptance_rate <=80 THEN '61-80'
ELSE 'Above 80'
END acceptance_range,
new_superhost,
count(*) as superhost_count
FROM acceptance_rate_cte
我对结果的期望是这样的:
acceptance_range | new_superhost | superhost_count
1-20 |真 | 15
1-20 |假 | 25
...
但是我收到如下错误消息:
Error running query Table name "acceptance_rate_cte" missing dataset while no default dataset is set in the request.
我 运行 你上面的查询和一些示例数据似乎大部分是正确的。
with acceptance_rate_cte AS
( SELECT
CAST(REPLACE(acceptance_rate,'%',"") AS int) AS new_acceptance_rate,
host_is_superhost AS new_superhost
FROM table1
WHERE acceptance_rate NOT IN ("N/A","0%")
ORDER BY new_acceptance_rate DESC
)
SELECT CASE WHEN new_acceptance_rate >0 AND new_acceptance_rate <= 20 then '1-20'
WHEN new_acceptance_rate >20 AND new_acceptance_rate <=40 then '21-40'
WHEN new_acceptance_rate >40 AND new_acceptance_rate<=60 THEN '41-60'
WHEN new_acceptance_rate >60 AND new_acceptance_rate <=80 THEN '61-80'
ELSE 'Above 80'
END acceptance_range,
new_superhost,
count(*) as superhost_count
FROM acceptance_rate_cte
GROUP BY acceptance_range, new_superhost;
我确实必须添加一个分组依据才能使其正确执行。根据您的错误,尽管我猜测您没有 运行 在同一会话中同时使用 CTE 和查询。当你同时执行 运行 时。