我有一个查询遇到此错误消息: 错误:标量子查询产生了多个元素
我想联接表示在不同时间段内发生的行为的表,但是普通联接似乎不起作用:
从中选择a.g,count(*)
(选择user_id作为用户,
(从中选择x.value.string_value
analytics_156934592.events_20180701
,unnest(event_params)为x,其中 x.key ='group')as g,(从中选择x.value.string_value
analytics_156934592.events_20180701
,unnest(event_params)为x,其中 x.key ='operation')作为操作来自
analytics_156934592.events_20180701
,其中event_name = 'book_now')a加入
(选择user_id作为用户,
(从中选择x.value.string_value
analytics_156934592.events_20180702
,unnest(event_params)为x,其中 x.key ='operation')作为操作来自
analytics_156934592.events_20180702
,其中event_name = 'book_now')ba.user = b.user
其中a.operation ='no_car'和b.operation ='confirm'
a.g
分组
不确定是否是使用Big Query Standard Sql进行联接的正确方法 同样,以前类似问题的解决方案对我也不起作用。
感谢您的帮助!
答案 0 :(得分:1)
谢谢!
我从朋友那里得到了一个解决方案,这是可行的:
select count(distinct a.user), count(distinct b.user_id)
from
(select
user_id as user
from `analytics_156934592.events_20180707`
join unnest(event_params) as x
join unnest(event_params) as y
where event_name = 'book_now'
and x.key = 'group'
and x.value.string_value = 'a'
and y.key = 'operation'
and y.value.string_value = 'no_car')a
left join
(select
user_id , event_date
from `analytics_156934592.events_*`
join unnest(event_params) as y
where event_name = 'launcher'
and y.key = 'operation'
and y.value.string_value = 'show'
AND REGEXP_EXTRACT(_TABLE_SUFFIX, r'(\d+)') BETWEEN '20180708' and '20180720')b
on a.user = b.user_id