【问题标题】:"Unrecognized name: m01_order_datetime_gmt0" error in BigQueryBigQuery 中出现“无法识别的名称:m01_order_datetime_gmt0”错误
【发布时间】:2018-09-28 06:18:19
【问题描述】:

下面是我收到错误的脚本

错误:无法识别的名称:m01_order_datetime_gmt0 at [9:19]

代码

`select
case
when number_of_bookings = 1 then '1'
when number_of_bookings = 2 then '2'
when number_of_bookings = 3 then '3'
else '>3' end as number_of_bookings,
count(user_id) as number_of_users,
date_trunc(date(m01_order_datetime_gmt0), month) as Booking_month
from
(select
 user_id,
 count(distinct order_id) number_of_bookings
from analyst_all_orders
where 1=1
and d181_business_platform_code is not null
and date(m01_order_datetime_gmt0) between '2018-03-01' AND '2018-08-31'
group by 1
order by 1) as a
group by 1
order by 1`

【问题讨论】:

  • 我无法给出确切的答案,但我会指出您在子查询中别名为a 的ORDER BY 要么不正确,要么至少毫无意义。你应该删除它。

标签: google-bigquery


【解决方案1】:

试试这个:

`select
case
when number_of_bookings = 1 then '1'
when number_of_bookings = 2 then '2'
when number_of_bookings = 3 then '3'
else '>3' end as number_of_bookings,
count(user_id) as number_of_users,
date_trunc(date(m01_order_datetime_gmt0), month) as Booking_month
from
(select
 user_id,
 count(distinct order_id) number_of_bookings
 , M01_ORDER_DATETIME_GMT0
from analyst_all_orders
where 1=1
and d181_business_platform_code is not null
and date(m01_order_datetime_gmt0) between '2018-03-01' AND '2018-08-31'
group by 1
order by 1) as a
group by 1
order by 1`

(如果子查询不将列传递给周围查询,则周围查询将不知道该列)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    相关资源
    最近更新 更多