104. MAU: Monthly active users

easy google

  • **************************************************************************************
  • *********************************************************************************************************

Table 1: session_mobile

Every time a user opens the mobile app (iOS, Android), a new session starts, it ends when the user leaves the app.

  col_name       | col_type
-----------------+---------------------
date             | date    
user_id          | bigint
session_id       | bigint
event            | varchar(20)

Table 2: session_web

Every time a user visits the website, a new session starts, it ends when the user leaves the site.

  col_name       | col_type
-----------------+---------------------
date             | date    
user_id          | bigint
session_id       | bigint
event            | varchar(20)

Sample results

   year    |   mon  | mau
-----------+--------+--------
2021       | 7      | 123
2021       | 8      | 234

Solution postgres

WITH session AS (
    SELECT * FROM session_web
    WHERE event NOT IN ('enter', 'exit')
    UNION ALL
    SELECT * FROM session_mobile
    WHERE event NOT IN ('enter', 'exit')
)
SELECT
    EXTRACT(YEAR FROM date) AS year,
    EXTRACT(MONTH FROM date) AS mon,
    COUNT(DISTINCT user_id) AS mau
FROM session
GROUP BY 1,2;
    

Explanation

This query is selecting data from two tables, session_web and session_mobile, and combining them into one table called "session". The data being selected is for events that are not "enter" or "exit".

Then, the query is extracting the year and month from the "date" column and counting the number of unique user IDs for each month and year. This count represents the monthly active users (MAU) for that particular month and year.

Finally, the results are grouped by year and month, so that you can see the monthly active user count for each month and year.

Expected results


More Google questions

ID Title Level FTPR
101 Average number of visits per user google easy
14%
102 Histogram by visit session duration google hard
17%
103 Median and average session duration by day of the week google medium
20%
105 Number of days gap between last two actions google hard
8%
106 Mobile vs. web google medium
10%
107 Customer count by platform google medium
17%
147 2 days streak customers google hard
13%
148 Most popular video category google medium
13%
149 fans by video category google easy
36%
150 Countries with above average customers google easy
15%
186 Average comments per question google easy
10%
187 Comment distribution at Google Forum google easy
17%
188 Top 1 popular question by department google hard
14%