提问人:Luiscri 提问时间:11/17/2023 更新时间:11/19/2023 访问量:47
标准 SQL - 具有时间限制的窗口
Standard SQL - windows with time constrains
问:
我正在运行一个窗口函数,该函数在标准 SQL 上如下所示:
SELECT *
FROM base_query
WHERE
(
event_page_type = "product"
AND (
-- Monthly price feature
event_name LIKE "fs_mp_%"
-- Add to cart events
OR event_name = "add_to_cart"
)
)
/*
Keep only those add_to_cart events which have a fs_mp event on the same session
*/
QUALIFY MAX(IF(event_name LIKE "fs_mp_%", 1, 0)) OVER (PARTITION BY session_id) = 1
我尝试使用此查询执行的操作是获取所有类似的事件,并且仅获取那些在同一会话中具有事件的事件。fs_mp_%
add_to_cart
fs_mp_%
但是,此逻辑不会检查事件发生之前。如果我想根据字段添加该逻辑,它会是什么样子?fs_mp_%
add_to_cart
server_timestamp
答:
-1赞
Luiscri
11/19/2023
#1
我找到了自己的路。我需要语句中的第二个条件:QUALIFY
QUALIFY
MAX(IF(event_name LIKE "fs_mp_%", 1, 0)) OVER (session) = 1
AND MIN(IF(event_name LIKE "fs_mp_%", server_timestamp, "9999-12-31")) OVER (session) < server_timestamp
WINDOW session AS (PARTITION BY session_id)
评论