Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Efficient Session Features in BigQuery

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Efficient Session Features in BigQuery. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

How would you handle and aggregate millions of transactional records in Google BigQuery to extract user session features efficiently?

Write a PostgreSQL query that produces one feature row per qualifying user session. Include only completed transactions from January 2025, then enrich the results with user attributes.

Output

  1. One row per qualifying user session with user_id, session_id, user_name, country, platform, event_count, total_amount, duration_seconds, and distinct_event_types.
  2. Order by user_id ascending, then session_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
user_nameVARCHAR(100)Display name of the user
countryVARCHAR(50)User country
platformVARCHAR(20)Primary betting platform
transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction event identifier
user_idINTEGERUser associated with the transaction
session_idVARCHAR(30)Application session identifier
event_tsTIMESTAMPTimestamp when the event occurred
event_typeVARCHAR(30)Type of user transaction event
amountNUMERIC(12,2) monetary amount associated with the event
statusVARCHAR(20)Processing status of the transaction
Tablestransactionsusers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results