arcs / tasks /readable /009 /task_readable.md
yanlinf's picture
Release ARCS dataset
1fb4e2d verified
|
Raw History Blame Contribute Delete
788 Bytes
# Task: 009
**Database:** retails
## Question
List the customer who made the highest number of purchases using rail shipping.
## Gold Query
```sql
WITH customer_rail_lineitems AS (
SELECT c.c_custkey,
c.c_name,
COUNT(*) AS rail_ship_count
FROM customer c
JOIN orders o ON c.c_custkey = o.o_custkey
JOIN lineitem l ON o.o_orderkey = l.l_orderkey
WHERE l.l_shipmode = 'RAIL'
GROUP BY c.c_custkey, c.c_name
)
SELECT c.c_custkey, c.c_name, c.rail_ship_count
FROM customer_rail_lineitems c
WHERE c.rail_ship_count = (
SELECT MAX(rail_ship_count) FROM customer_rail_lineitems
);
```
**Execution Result:**
| c_custkey | c_name | rail_ship_count |
|-------------|--------------------|-------------------|
| 63035 | Customer#000063035 | 28 |
*1 rows*