Multi-step SQL transformations come up often in reporting and data preparation, especially when you need to calculate an intermediate result before applying final business logic. In PostgreSQL, subqueries are a common way to make that logic easier to read and validate.
Explain how you would use subqueries to simplify a multi-step SQL transformation. Your answer should describe when a subquery is useful, how it helps separate intermediate calculations from final output logic, and how you would structure nested queries in a clear way. You should also explain the difference between using a subquery in the FROM clause versus in the WHERE clause.
Use a simple example such as first aggregating transaction data and then filtering or ranking the aggregated result. You do not need to discuss advanced optimization internals, but you should show that you understand readability, maintainability, and common tradeoffs.