SQL
Lab
Google Google Chrome Interview Question 07

Browser
Session
Time

Find total browsing time per user.

Table Schema

Inspect
Table

interactive
ColumnType
session_idinteger
user_idinteger
duration_minutesinteger

Sample Data

Input
Output

Sample Input: browser_sessions
session_iduser_idduration_minutes
110160
210190
310245
410380
510130
Expected Output
user_idtotal_time
101180
10245
10380

SQL Editor

Run
Query

postgresql
Waiting for query

user_idtotal_time
101180
10245
10380

Hints

Unlock
Clues

Hint 01: Total time is a SUM.
Hint 02: Aggregate by user_id.
Hint 03: Alias the result as total_time.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT
  user_id,
  SUM(duration_minutes) AS total_time
FROM browser_sessions
GROUP BY user_id;

Explanation

Step By
Step

01

Group sessions by user.

02

Add all duration_minutes.

03

Return one row per user.

Related Questions

Keep
Solving