PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches

Quick Overview

This question evaluates proficiency in SQL data manipulation, including aggregation, window functions, joins, and temporal calculations for analyzing event and session logs.

  • Medium
  • Amazon
  • Data Manipulation (SQL/Python)
  • Data Scientist

Analyze User Engagement with SQL Queries

Company: Amazon

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Onsite

events +----------+---------+---------------------+ | event_id | user_id | event_time | +----------+---------+---------------------+ | 1 | 101 | 2023-01-01 09:00:00 | | 2 | 101 | 2023-01-01 10:30:00 | | 3 | 102 | 2023-01-02 08:15:00 | | 4 | 103 | 2023-01-03 12:45:00 | +----------+---------+---------------------+ ​ sessions +-----------+---------+---------------------+---------------------+ | session_id| user_id | session_start | session_end | +-----------+---------+---------------------+---------------------+ | 1001 | 101 | 2023-01-01 08:45:00 | 2023-01-01 10:45:00 | | 1002 | 102 | 2023-01-02 08:00:00 | 2023-01-02 09:00:00 | | 1003 | 103 | 2023-01-03 08:30:00 | 2023-01-03 13:30:00 | +-----------+---------+---------------------+---------------------+ ##### Scenario You are a data analyst exploring product-usage logs and session metadata to understand user engagement. ##### Question Q1. Using table events, write a SQL query that returns the total number of events generated by each user (user_id). Q2. Using table events, return for every user_id the earliest event_time and the latest event_time observed. Q3. Using tables events and sessions, write a SQL query that finds the user_id whose single session has the longest duration (session_end – session_start); return both the user_id and that duration. ##### Hints Window functions, GROUP BY, TIMESTAMPDIFF; join events e ON e.user_id = s.user_id when needed.

Quick Answer: This question evaluates proficiency in SQL data manipulation, including aggregation, window functions, joins, and temporal calculations for analyzing event and session logs.

Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find recommended friend pairs by shared songs - Amazon (medium)
  • Find recommended friend pairs by shared listening - Amazon (easy)
  • Write SQL window functions for D7 retention - Amazon (medium)
  • Find daily first-order merchants with SQL - Amazon (Medium)
  • Design student–course data models and SQL - Amazon (Medium)