我试图做多个嵌套子查询。首先找到带有角色" Person"的小写名称,然后找到那些人拥有的session_ids
。使用session ids
列表,我想根据session ids
select
U.session_id,
U.session_date,
U.email
from data.usage U
left outer join
select
distinct M.session_id
from data.usage M
where email like '%gmail.com%'
and data_date >= '20180101'
and name in
(
select
lower(name)
from data.users
where role like 'Person%'
and isactive = TRUE
and data_date = '20180412'
)
on U.session_id = M.session_id
我能够让子查询自行运行,并生成session_ids
列表,我尝试使用where session_id in (subqueries)
,但这并不是工作。我也尝试过where exists
或left outer join
之类的内容,但我无法让其中的任何内容发挥作用。
答案 0 :(得分:1)
在您向M写入的所有查询的左外连接保留别名后,再次运行查询。
尝试在查询下方运行
select
U.session_id,
U.session_date,
U.email
from data.usage U
left outer join
(select
distinct M.session_id
from data.usage M
where email like '%gmail.com%'
and data_date >= '20180101'
and name in
(
select
lower(name)
from data.users
where role like 'Person%'
and isactive = TRUE
and data_date = '20180412'
))M
on U.session_id = M.session_id