arcs / tasks /readable /026 /task_readable.md
yanlinf's picture
Release ARCS dataset
1fb4e2d verified
|
Raw History Blame Contribute Delete
1.09 kB
# Task: 026
**Database:** professional_basketball
## Question
For each team that Marcus Williams played for, compute his aggregate field goal percentage.
## Gold Query
```sql
WITH season_stats AS (
SELECT t.tmID, t.name, pt.year,
CASE WHEN SUM(pt.fgAttempted) = 0 THEN 0
ELSE CAST(SUM(pt.fgMade) AS REAL) / SUM(pt.fgAttempted)
END as field_goal_percentage
FROM players_teams pt
JOIN players p ON pt.playerID = p.playerID
JOIN teams t ON pt.tmID = t.tmID AND pt.year = t.year
WHERE p.firstName = 'Marcus'
AND p.lastName = 'Williams'
AND p.college = 'Connecticut'
AND p.birthDate = '1985-12-03'
GROUP BY t.tmID, t.name, pt.year
)
SELECT tmID, name, AVG(field_goal_percentage) as field_goal_percentage
FROM season_stats
GROUP BY tmID, name;
```
**Execution Result:**
| tmID | name | field_goal_percentage |
|--------|-----------------------|-------------------------|
| GSW | Golden State Warriors | 0.23529412 |
| MEM | Memphis Grizzlies | 0.38376384 |
| NJN | New Jersey Nets | 0.38754914 |
*3 rows*