001Level 1

Chapter 7 · CTEs

03. Top Transaction Amount by Type (CTE)

Medium20 XPFinance

For each transaction type, find the single transaction with the highest amount. Use a CTE with ROW_NUMBER to rank transactions within each type. Return the type, transaction id, account_id, amount, and transaction_date. Sort by amount descending.

Tables

  • PKidINT
  • FKaccount_id→ accounts.idINT
  • transaction_dateTEXT
  • typeTEXT
  • amountREAL
  • balance_afterREAL
  • descriptionTEXT
  • reference_numberTEXT

Need help?

Ask Sol

AI tutor — looks at your current query and nudges you, without spoiling the answer.

Solution

Try the hints first — solving it yourself is what makes it stick.

Peek at the solution?

You can still earn the XP afterwards by submitting a working query — but you'll learn more if you give it one more try.