Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Portfolio Exposure Summary

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

Your question is SQL for Portfolio Exposure Summary. 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

Barclays risk reporting needs a counterparty-level view of exposure across active portfolios. Write a PostgreSQL query that preserves counterparties with no current exposure.

Requirements

  1. Join counterparties to active portfolios and current open positions as of 2025-06-30.
  2. Return each counterparty's active portfolio count, open position count, and total exposure.
  3. Treat missing exposure as zero and preserve counterparties with no matching active portfolios or positions.
  4. Sort by total exposure descending, then counterparty name ascending.

Schema

counterparties
ColumnTypeDescription
counterparty_idPKINTUnique counterparty identifier
counterparty_nameVARCHAR(100)Counterparty legal or reporting name
regionVARCHAR(50)Primary operating region
portfolios
ColumnTypeDescription
portfolio_idPKINTUnique portfolio identifier
counterparty_idINTOwning counterparty identifier
portfolio_nameVARCHAR(100)Portfolio reporting name
portfolio_statusVARCHAR(20)Portfolio lifecycle status
positions
ColumnTypeDescription
position_idPKINTUnique position identifier
portfolio_idINTRelated portfolio identifier
position_dateDATEPosition valuation date
position_statusVARCHAR(20)Position lifecycle status
asset_classVARCHAR(40)Position asset class
exposure_amountNUMERIC(18,2)Signed exposure amount in reporting currency
Tablescounterpartiesportfoliospositions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results