Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Above Average Query

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

Your question is SQL Above Average Query. 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

Union Bank wants to review approved loan applications whose requested amount is above the average amount across all approved applications. Write a PostgreSQL query using the loan and branch data.

Requirements

  1. Consider only applications with status = 'Approved' when calculating the average and filtering results.
  2. Return each qualifying loan's ID, customer ID, branch name, and loan amount.
  3. Exclude applications whose branch does not exist in the branch directory, and order results by loan amount from highest to lowest.

Schema

loan_applications
ColumnTypeDescription
loan_idPKINTUnique loan application identifier
customer_idVARCHAR(20)Union Bank customer identifier
branch_idINTAssociated branch identifier
loan_amountNUMERIC(12,2)Requested loan amount
statusVARCHAR(20)Current application status
branches
ColumnTypeDescription
branch_idPKINTUnique branch identifier
branch_nameVARCHAR(100)Union Bank branch name
cityVARCHAR(60)Branch city
Tablesloan_applicationsbranches
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results