Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 3 Outages Per Region

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

Your question is Top 3 Outages Per Region. 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

Nokia NetAct stores network outage events that operations teams use to identify recurring reliability problems. Write a PostgreSQL query to find the three longest completed outage events for every region.

Requirements

  1. Join outage_events to regions and display the region name.
  2. Calculate each completed outage duration in hours from started_at and ended_at.
  3. Use a window function to rank outages independently within each region, return only ranks 1 through 3, and sort ties deterministically by outage_id.
  4. Exclude ongoing outages, invalid timestamps, and events whose region does not exist in regions.

Schema

regions
ColumnTypeDescription
region_idPKINTEGERUnique regional identifier
region_nameVARCHAR(100)Nokia network operating region
outage_events
ColumnTypeDescription
outage_idPKINTEGERUnique outage event identifier
region_idINTEGERReferences regions.region_id
outage_typeVARCHAR(40)Network outage classification
started_atTIMESTAMPOutage start timestamp
ended_atTIMESTAMPRecovery timestamp, NULL for ongoing outages
Tablesregionsoutage_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results