Knowee
Questions
Features
Study Tools

WITH install AS ( SELECT el.user_id, el.create_time FROM event_logs el WHERE el.event_id = 'onboarding_login_view' AND el.referrer = 'plugin_installed' ) --first_usage_after_installed AS ( SELECT i.user_id, i.create_time, COALESCE(min(cr.event_time), toDateTime('1970-01-01 00:00:00')) AS first_event_time FROM install i LEFT JOIN chat_records cr ON i.user_id = cr.user_id WHERE cr.event_time > i.create_time GROUP BY i.user_id, i.create_time帮我修改代码,我要展现出用户安装后第一次使用的功能,即使没有使用也要

Question

WITH install AS ( SELECT el.user_id, el.create_time FROM event_logs el WHERE el.event_id = 'onboarding_login_view' AND el.referrer = 'plugin_installed' )

--first_usage_after_installed AS ( SELECT i.user_id, i.create_time, COALESCE(min(cr.event_time), toDateTime('1970-01-01 00:00:00')) AS first_event_time FROM install i LEFT JOIN chat_records cr ON i.user_id = cr.user_id WHERE cr.event_time > i.create_time GROUP BY i.user_id, i.create_time帮我修改代码,我要展现出用户安装后第一次使用的功能,即使没有使用也要

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the modified code:

WITH install AS (
    SELECT 
        el.user_id,
        el.create_time
    FROM 
        event_logs el
    WHERE 
        el.event_id = 'onboarding_login_view' 
        AND el.referrer = 'plugin_installed'
),

first_usage_after_installed AS (
    SELECT
        i.user_id,
        i.create_time,
        COALESCE(min(cr.event_time), toDateTime('1970-01-01 00:00:00')) AS first_event_time
    FROM 
        install i
    LEFT JOIN 
        chat_records cr ON i.user_id = cr.user_id
    WHERE 
       cr.event_time > i.create_time
    GROUP BY 
        i.user_id, i.create_time
)

SELECT 
    i.user_id,
    i.create_time AS install_time,
    f.first_event_time AS first_usage_time
FROM 
    install i
LEFT JOIN 
    first_usage_after_installed f ON i.user_id = f.user_id AND i.create_time = f.create_time

This code first creates a temporary table install to store the user_id and create_time of users who installed the plugin. Then it creates another temporary table first_usage_after_installed to store the user_id, create_time and the time of the first event after installation. If there is no event after installation, the time will be set to '1970-01-01 00:00:00'. Finally, it selects the user_id, install_time and first_usage_time from these two tables. If a user has not used the plugin after installation, the first_usage_time will be '1970-01-01 00:00:00'.

This problem has been solved

Similar Questions

SELECT DISTINCT el.device_id, DATE(el.create_time) date, CASE WHEN el.platform IN ('') THEN 'null' ELSE 'unknown' END AS platform_div, CASE WHEN el.event_id='home_page_view' THEN 1 ELSE 0,caseWHEN ud.country ='' THEN 'unknown' ELSE 'developing_country' END AS country_div FROM event_logs el JOIN user_devices ud ON el.device_id = ud.device_id我要如何在查询结果中加入每个device_id使用过的次数

SELECT date(create_time) date, count(distinct device_id) FROM event_logs where event_id='home_page_view' GROUP BY date order by date desc union SELECT date(create_time) date, count(device_id) FROM event_logs where event_id='home_page_view' GROUP BY date order by date desc

Table: ActivityColumn NameTypeplayer_idintdevice_idintevent_datedategames_playedint(player_id, event_date) is the primary key of this table.This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.Write a SQL query that reports the device that is first logged in for each player.The query result format is in the following example:Activity table:player_iddevice_idevent_idgames_played122016-03-015122016-05-026232017-06-251312016-03-020342018-07-035Result table:player_iddevice_id122331Optionsselect player_id, device_idfrom Activitywhere (player_id, event_date) in (select player_id, min(event_date)group by player_id);select player_id, device_idfrom Activity (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);select device_idfrom Activity where (player_id, event_date) in (select player_id, min(event_date)from Activity group by player_id);

Game Play Analysis ITable: ActivityColumn NameTypeplayer_idintdevice_idintevent_datedategames_playedint(player_id, event_date) is the primary key of this table.This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.Write an SQL query that reports the first login date for each player.The query result format is in the following example:Activity table:player_iddevice_idevent_idgames_played122016-03-015122016-05-026232017-06-251312016-03-020342018-07-035Result table:player_idfirst_login12016-03-0122017-06-2532016-03-02Optionsselect player_id, min(event_date) as first_loginfrom Activityby player_idorder by player_id;select player_id, min(event_date) as first_loginfrom Activitygroup by player_idorder by player_id;select player_id, min(event_date) as first_loginof Activitygroup by player_idorder by player_id;select min(event_date) as first_loginfrom Activitygroup by player_idorder by player_id;

Game Play Analysis IITable: ActivityColumn NameTypeplayer_idintdevice_idintevent_datedategames_playedint(player_id, event_date) is the primary key of this table.This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.Write a SQL query that reports the device that is first logged in for each player.The query result format is in the following example:Activity table:player_iddevice_idevent_idgames_played122016-03-015122016-05-026232017-06-251312016-03-020342018-07-035Result table:player_iddevice_id122331Optionsselect device_idfrom Activity where (player_id, event_date) in (select player_id, min(event_date)from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in (select player_id, min(event_date)group by player_id);select player_id, device_idfrom Activity (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);select player_id, device_idfrom Activitywhere (player_id, event_date) in ( select player_id, min(event_date) from Activity group by player_id);Finish

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.