# Regional Footprint

> Every node costs money. Know what you own.

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

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

The capacity team needs a headcount of nodes in the primary US region. How many infrastructure nodes are deployed in 'us-east-1'?

## Worked solution and explanation

### Why this problem exists in real interviews

This is a basic filtered COUNT query. It tests the simplest form of aggregation with a WHERE clause.

---

### Break down the requirements

#### Step 1: Filter and count

`WHERE region = 'us-east-1'` restricts to the target region. `COUNT(*)` returns the headcount.

---

### The solution

**Filtered count**

```sql
SELECT COUNT(*) AS node_count
FROM infra_nodes
WHERE region = 'us-east-1'
```

> **Cost Analysis**
>
> Scan of 4K rows. Trivially fast. An index on `region` would enable an index-only count.

> **Interviewers Watch For**
>
> Whether the candidate adds unnecessary complexity. This is a one-line query; anything more is over-engineering.

> **Common Pitfall**
>
> Using `COUNT(node_id)` instead of `COUNT(*)` is functionally equivalent here (assuming node_id is NOT NULL), but `COUNT(*)` is the standard for counting rows.

---

## Common follow-up questions

- What if you needed the count for all regions? _(GROUP BY region, no WHERE clause.)_
- What is the performance difference between COUNT(*) and COUNT(column)? _(COUNT(*) counts all rows; COUNT(column) must check for NULLs. COUNT(*) is typically faster.)_
- How would you verify the count is correct? _(Cross-reference with a SELECT * query or check constraints.)_

## Related

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