Business Context
DRW's quantitative analytics team compares Company A's quarterly profitability in EUR, although source profit records are stored in USD. Exchange rates vary by date, so each profit record must be converted before aggregation.
Task
Write a PostgreSQL query that calculates the percentage increase in Company A's EUR-denominated profit from the first to the last month of Q1 2025.
Requirements
- Join companies, profit records, and daily FX rates.
- Convert each USD profit using
profit_usd * eur_per_usd, then aggregate by month.
- Ignore records with missing profit or FX values and exclude dates outside Q1 2025.
- Return the first month, last month, EUR profit for each, and the percentage increase rounded to two decimals.
Output details
- Return exactly one row with columns
first_month, last_month, first_eur_profit, last_eur_profit, and percentage_increase, in that order.
- Use the earliest and latest months having qualifying records, rather than assuming January and March are present.
- Include
2025-01-01 and exclude 2025-04-01 when defining Q1 2025.
- Preserve aggregated EUR profits without additional rounding, and round only
percentage_increase to two decimal places.
- Return
NULL for percentage_increase when the first EUR profit equals 0.