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 for Indirect Tax Calculations
00:00
5 left

SQL for Indirect Tax Calculations

HardSQL · PostgreSQL

Problem

Write a SQL query to calculate indirect taxation amounts and related calculations from transactional data.

Use posted transactions only. Apply the tax rate effective on each transaction date, account for valid customer exemptions, and preserve transactions without matching jurisdiction or rate data.

Output

  1. One row per posted transaction, ordered by transaction date and transaction ID
  2. Include transaction ID, jurisdiction name, gross amount, exempt amount, taxable amount, state tax, local tax, total tax, tax as a percentage of gross amount, prior transaction tax, monthly jurisdiction tax, and cumulative jurisdiction tax
  3. Exclude void and pending transactions; retain NULL jurisdiction names and zero tax where no applicable rate exists

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
customer_idINTCustomer associated with the transaction
jurisdiction_idINTTax jurisdiction identifier
transaction_dateDATETransaction date
taxable_amountDECIMAL(12,2)Gross transaction amount before exemption
transaction_typeVARCHAR(20)Sale or refund classification
exemption_codeVARCHAR(20)Customer exemption code
statusVARCHAR(20)Transaction processing status
tax_rates
ColumnTypeDescription
tax_rate_idPKINTUnique tax rate identifier
jurisdiction_idINTJurisdiction using the rate
effective_fromDATERate start date
effective_toDATERate end date
state_rateDECIMAL(8,5)State tax rate as a decimal
local_rateDECIMAL(8,5)Local tax rate as a decimal
jurisdictions
ColumnTypeDescription
jurisdiction_idPKINTUnique jurisdiction identifier
jurisdiction_nameVARCHAR(100)Tax jurisdiction name
country_codeVARCHAR(2)Country code
tax_exemptions
ColumnTypeDescription
exemption_idPKINTUnique exemption record identifier
customer_idINTCustomer receiving the exemption
exemption_codeVARCHAR(20)Exemption code
exemption_pctDECIMAL(5,4)Exempt percentage as a decimal
valid_fromDATEExemption start date
valid_toDATEExemption end date
Tablestransactionstax_ratesjurisdictionstax_exemptions
Interviewer

Your question is SQL for Indirect Tax Calculations. 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.