Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Average Transaction by Country
00:00
5 left

Average Transaction by Country

MediumSQL · PostgreSQL

Problem

Write a query to find the average transaction amount for each country on WePay, excluding transactions marked as fraud.

Use the provided WePay country and transaction data. Include countries with no eligible transactions, returning a NULL average for those countries.

Output

  1. One row per country, including countries without eligible transactions.
  2. Columns: country and average_transaction_amount.
  3. Round the average to two decimal places and sort alphabetically by country.

Schema

countries
ColumnTypeDescription
country_idPKINTUnique country identifier
country_nameVARCHAR(100)Country name displayed in reports
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
country_idINTCountry associated with the transaction
amountDECIMAL(12,2)Transaction amount
is_fraudBOOLEANWhether the transaction was marked as fraud
Tablescountriestransactions
Interviewer

Your question is Average Transaction by Country. 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.