Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Window Functions for Top Connections
00:00
5 left

Window Functions for Top Connections

MediumSQL · PostgreSQL

Problem

Write a query using window functions to find the top active connections per data center node.

Use the provided node and connection tables. Include only active connections and return the two highest-bandwidth connections for each node.

Output

  1. One row per selected active connection, with node_id, node_code, connection_id, connection_name, bandwidth_mbps, and connection_rank
  2. Rank separately within each node, breaking bandwidth ties by the lower connection_id
  3. Sort by node_id, then connection_rank, then connection_id

Schema

data_center_nodes
ColumnTypeDescription
node_idPKINTUnique identifier for the data center node
node_codeVARCHAR(30)Operational code for the node
regionVARCHAR(40)Geographic region containing the node
node_connections
ColumnTypeDescription
connection_idPKINTUnique identifier for the connection
node_idINTData center node associated with the connection
connection_nameVARCHAR(50)Operational name of the connection
statusVARCHAR(20)Current connection state
bandwidth_mbpsINTConfigured connection bandwidth in megabits per second
Tablesdata_center_nodesnode_connections
Interviewer

Your question is Window Functions for Top Connections. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.