# Top 10 Batch Jobs

> The ten biggest batch jobs.

Canonical URL: <https://datadriven.io/problems/top_10_batch_jobs>

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

Show the top 10 batch jobs by rows processed. If jobs are tied, they should share the same rank without gaps. Return each job's name and rank, from lowest rank number to highest, then alphabetically by job name.

## Worked solution and explanation

### Why this problem exists in real interviews

Simple top-N with ORDER BY and LIMIT is the most basic ranking pattern. Interviewers use it to verify you can sort and limit correctly without over-engineering.

---

### Break down the requirements

#### Step 1: Order by the size metric

`ORDER BY output_bytes DESC` puts the largest batch jobs first.

#### Step 2: Limit to 10

`LIMIT 10` returns exactly the top 10 rows.

---

### The solution

**Simple ORDER BY with LIMIT**

```sql
SELECT job_name, output_bytes
FROM batch_jobs
ORDER BY output_bytes DESC
LIMIT 10
```

> **Cost Analysis**
>
> A top-N sort is O(N log 10). An index on `output_bytes DESC` allows reading the top 10 directly from the index.

> **Interviewers Watch For**
>
> Simplicity is valued. Using a window function when LIMIT works signals over-engineering.

> **Common Pitfall**
>
> Assuming the size column has a unique constraint. If multiple jobs have the same `output_bytes`, LIMIT 10 arbitrarily picks among ties.

---

## Common follow-up questions

- What if you needed the top 10 per job category? _(Tests switching from LIMIT to ROW_NUMBER with PARTITION BY.)_
- How would you handle ties at position 10? _(Tests when to use DENSE_RANK vs. LIMIT.)_
- What if output_bytes has NULLs? _(Tests NULL sort behavior.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/top_10_batch_jobs)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.