NewThe Learning module is now liveSee what's new

Description

Table: transactions

+-----------------+---------+
| Column Name     | Type    |
+-----------------+---------+
| transaction_id  | integer |
| customer_id     | integer |
| purchase_amount | integer |
+-----------------+---------+

transaction_id is the primary key. Each row represents one purchase transaction by a customer.

Write a query to find each customer's highest value transaction. Return customer_id and purchase_amount (the maximum per customer), sorted by purchase_amount in descending order.

The result format is shown below.

Example

Input:

transactions table:
+----------------+-------------+-----------------+
| transaction_id | customer_id | purchase_amount |
+----------------+-------------+-----------------+
| 1              | 1           | 150             |
| 2              | 1           | 35.90           |
| 3              | 2           | 349.99          |
| 4              | 2           | 199.95          |
| 5              | 2           | 551.20          |
| 6              | 3           | 13.30           |
+----------------+-------------+-----------------+

Output:

+-------------+-----------------+
| customer_id | purchase_amount |
+-------------+-----------------+
| 2           | 551.20          |
| 1           | 150             |
| 3           | 13.30           |
+-------------+-----------------+

Explanation:
Customer 1 has transactions of 150 and 35.90, so the max is 150. Customer 2 has three transactions, so the max is 551.20. Customer 3 has one transaction, so the max is 13.30. Results are sorted by purchase amount in descending.


Accepted
9/12
Acceptance Rate75.0%
Test Cases
Input
-
Output
-
Expected
-