我有一张想要的桌子: 1)检查符合要求的访客(VisitorID) 2)获取那些访问者访问我网站的所有时间。
我一直在尝试将所有条件与我的第一个查询以及另一个获得其余相关变量的查询合并在一起。
SELECT ID, h.Info, h.Action
FROM `table` as A,
UNNEST (hits) as h
WHERE (h.Info LIKE '%PPP%'
OR h.Info LIKE '%BBB%'
OR h.Info LIKE '%SSS%'
OR h.Info LIKE '%FFF%') AND
h.Category LIKE '%Lock%' AND
(h.Action LIKE '%Regist%' OR h.Action LIKE '%NotR%') AND
h.Label LIKE '%Success%'
JOIN
SELECT ID, h.Info, h.Action, time, visits, EXTRACT(TIME FROM TIMESTAMP_SECONDS(StartTime)) AS time_visit, PARSE_DATE("%Y%m%d", date) AS date_visit
FROM `table`,
UNNEST (hits) as h
WHERE (h.Info LIKE '%PPP%'
OR h.Info LIKE '%BBB%'
OR h.Info LIKE '%SSS%'
OR h.Info LIKE '%FFF%') AND
date > "20190529") AS B ON A.ID = B.ID
我已多次更改JOIN(包括/不包括方括号),并且我的想法已用完。
答案 0 :(得分:1)
我将继续使用CTE版本
with cte as
(
SELECT ID, h.Info, h.Action
FROM `table` as A,
UNNEST (hits) as h
WHERE (h.Info LIKE '%PPP%'
OR h.Info LIKE '%BBB%'
OR h.Info LIKE '%SSS%'
OR h.Info LIKE '%FFF%') AND
h.Category LIKE '%Lock%' AND
(h.Action LIKE '%Regist%' OR h.Action LIKE '%NotR%') AND
h.Label LIKE '%Success%'
),
cte1 as
(
SELECT ID, h.Info, h.Action, time, visits, EXTRACT(TIME FROM TIMESTAMP_SECONDS(StartTime)) AS time_visit, PARSE_DATE("%Y%m%d", date) AS date_visit
FROM `table`,
UNNEST (hits) as h
WHERE (h.Info LIKE '%PPP%'
OR h.Info LIKE '%BBB%'
OR h.Info LIKE '%SSS%'
OR h.Info LIKE '%FFF%') AND
date > "20190529"
) select cte.*,cte1.* from cte join cte1 on cte.id=cte1.id