Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Queries for Monthly Counts

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

Your question is SQL Queries for Monthly Counts. Start with the requirements and the three 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

Evidation Health uses member activity records to monitor engagement in the Evidation platform. Analyze activity recorded in Seattle for members whose participation is currently consented.

Write a PostgreSQL query that produces monthly Seattle activity counts and identifies the month or months with the highest count.

Requirements

  1. Join activity records to participant consent information and the city reference table.
  2. Include only records for Seattle, consented participants, and non-null recording dates.
  3. Return one row per month with the month formatted as YYYY-MM and the activity count.
  4. Include the prior month's count, the month-over-month change, and a flag identifying peak month ties.
  5. Use PostgreSQL syntax and state that the query is written for PostgreSQL.

Schema

activity_events
ColumnTypeDescription
event_idPKINTEGERActivity record identifier
user_idINTEGEREvidation member identifier
recorded_onDATEDate the activity was recorded
cityVARCHAR(80)City associated with the activity
participants
ColumnTypeDescription
user_idPKINTEGERMember identifier
consent_statusVARCHAR(20)Current participation consent status
city_reference
ColumnTypeDescription
city_namePKVARCHAR(80)Canonical city name
regionVARCHAR(80)State or region
Tablesactivity_eventsparticipantscity_reference
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results