简体   繁体   English

BigQuery:[CTE 表名称] 缺少数据集,而请求中未设置默认数据集

[英]BigQuery: [CTE Table name] missing dataset while no default dataset is set in the request

My original table has: (1) acceptance_rate - string, percentage (2) host_is_superhost - boolean我的原始表有:(1) acceptance_rate - 字符串,百分比 (2) host_is_superhost - boolean

I wanted to convert (1) acceptance_rate to integer without the %, so I created a CTE as follow:我想将 (1) acceptance_rate 转换为不带 % 的 integer,因此我创建了一个 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;

New CTE table looks like:新的 CTE 表如下所示:

new_acceptance_rate | new_acceptance_rate | new_superhost新超级房东

100 | 100 | true真的

90 | 90 | true真的

95 | 95 | false...错误的...

NEXT, I wanted to create a table to group all the new_acceptance_rate into buckets of 20 and then count how many true or false are within those buckets.接下来,我想创建一个表以将所有 new_acceptance_rate 分组到 20 个桶中,然后计算这些桶中有多少 true 或 false。 So I did this:所以我这样做了:

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

My expectation for the result is to look like this:我对结果的期望是这样的:

acceptance_range |接受范围 | new_superhost |新超级房东 | superhost_count superhost_count

1-20 | 1-20 | true |真 | 15 15

1-20 | 1-20 | false |假 | 25 25

... ...

But instead i received an error msg as follow:但相反,我收到了一条错误消息,如下所示:

Error running query Table name "acceptance_rate_cte" missing dataset while no default dataset is set in the request.运行查询时出错 表名“acceptance_rate_cte”缺少数据集,而请求中未设置默认数据集。

I ran your query above with some sample data it seems to be mostly correct.我在上面用一些样本数据运行了你的查询,它似乎大部分是正确的。

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;   

I did have to add a group by in order for it to execute properly.我确实必须添加一个分组依据才能使其正确执行。 Based on your error though my guess is you have not run both the CTE and query together in the same session. When you execute run both at the same time.根据你的错误,虽然我的猜测是你没有在同一个 session 中同时运行 CTE 和查询。当你执行时同时运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM