# Find the Fifth Largest Cost

> Not the biggest. Not the smallest. The fifth.

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

Domain: SQL · Difficulty: medium · Seniority: L4

## Problem

The FinOps team is investigating spending tiers and needs to isolate the fifth-highest cloud cost amount. If multiple line items share that amount, include all of them.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests basic querying against `cloud_costs`. The interviewer checks that you can read a schema and write correct SQL.

---

### Break down the requirements

#### Step 1: Identify output columns

Select the columns from `cloud_costs` matching the prompt requirements.

#### Step 2: Apply any filters or ordering

Add WHERE and ORDER BY as specified.

---

### The solution

**Basic query with ordering**

```sql
SELECT cost_id, provider, svc_name, region, amount
FROM cloud_costs
ORDER BY cost_id
LIMIT 100
```

> **Cost Analysis**
>
> Full scan of `cloud_costs` with LIMIT to bound the result size.

> **Interviewers Watch For**
>
> The interviewer checks basic SQL syntax and schema reading ability.

> **Common Pitfall**
>
> Forgetting ORDER BY leaves the output in an arbitrary, non-deterministic order.

---

## Common follow-up questions

- What if the table were empty? _(Tests edge case handling.)_
- How would you add a filter? _(Tests WHERE clause construction.)_
- What if some columns contain NULLs? _(Tests NULL awareness.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/find_the_fifth_largest_cost)
- [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.