Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL Multi-Concept Query
00:00
5 left

SQL Multi-Concept Query

HardSQL · PostgreSQL

Problem

Applied Data Finance needs a servicing report for loans originated through its lending platform. Write a PostgreSQL query that identifies loans with the second-highest distinct principal amount within each product and combines borrower, product, and payment information.

Requirements

  1. Rank distinct loan principal amounts within each product and retain every loan tied for second place.
  2. Display each origination date as YYYY-MM-DD using PostgreSQL date formatting.
  3. Return the borrower name, product name, principal amount, total non-null payments, and the most recent payment date and amount.
  4. Include loans without payments, showing a total payment amount of 0 and NULL for latest payment fields.
  5. Sort by product name, then loan ID.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique borrower identifier
customer_nameVARCHAR(100)Borrower full name
emailVARCHAR(255)Borrower email address
products
ColumnTypeDescription
product_idPKINTUnique lending product identifier
product_nameVARCHAR(100)Name of the Applied Data Finance lending product
loans
ColumnTypeDescription
loan_idPKINTUnique loan identifier
customer_idINTReferences customers.customer_id
product_idINTReferences products.product_id
principal_amountNUMERIC(12,2)Approved loan principal
origination_dateDATEDate the loan was originated
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
loan_idINTReferences loans.loan_id
payment_dateDATEDate the payment was received
payment_amountNUMERIC(12,2)Payment amount received
Tablescustomersproductsloanspayments
Interviewer

Your question is SQL Multi-Concept Query. Start with the requirements and the four 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.