Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
CTE Merchant Volume Share
00:00
5 left

CTE Merchant Volume Share

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate the percentage of total transaction volume contributed by each merchant, utilizing a WITH statement (Common Table Expression).

Use the provided merchant and transaction records. Include merchants with no matching transactions, and calculate percentages from transactions associated with listed merchants.

Output

  1. One row per merchant, including merchants with zero volume.
  2. Columns: merchant_name, transaction_volume, and percentage_of_total_volume.
  3. Round the percentage to two decimal places.
  4. Order by percentage descending, then merchant name ascending.

Schema

merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)Merchant display name
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
merchant_idINTMerchant associated with the transaction
transaction_volumeDECIMAL(12,2)Transaction monetary volume
Tablesmerchantstransactions
Interviewer

Your question is CTE Merchant Volume Share. 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.