# Top 25 SQL Data Engineering Interview Questions

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/blog/top-sql-data-engineering-interview-questions
Source observed: 2026-11-04T22:03:12.471Z
Last checked: 2026-11-04T22:03:12.471+00:00
Indexed: 2026-11-06T11:27:54.201+00:00

---

# Top 25 SQL Data Engineering Interview Questions

We created this guide for people preparing for data engineering interviews. SQL is a fundamental topic at every level. The guide contains practice prompts and PostgreSQL-style solutions covering beginner, intermediate, advanced, and performance-optimization topics.

We assembled the examples with insights from data engineers, data scientists, and machine learning engineers at Meta, Google, Dropbox, Amazon, and top startups. The examples focus on SQL for relational databases; with small syntax adjustments, many queries can also run in distributed environments such as [Amazon Athena](https://aws.amazon.com/athena/?ref=exponent-blog.ghost.io) over Amazon S3 or in Spark SQL.

## How to use this guide

Use the linked [SQL interview questions](https://www.aced.io/questions?sortBy=most-popular&type=sql&ref=exponent-blog.ghost.io), write your own solution first, then compare it with the query and explanation for each exercise. Our [SQL interview course](https://www.aced.io/courses/sql-interviews?src=nav&ref=exponent-blog.ghost.io) and [data engineering course](https://www.aced.io/courses/data-engineering?ref=exponent-blog.ghost.io) provide additional practice.

## Beginner SQL

Early-career interviews commonly test:

- Filtering with `WHERE`.
- Joining tables with `INNER JOIN` and `LEFT JOIN`.
- Aggregating with `COUNT()`, `SUM()`, `AVG()`, `MIN()`, and `MAX()`.
- Grouping with `GROUP BY`.
- Sorting with `ORDER BY`.

### 1. LinkedIn Job Applicants

Find candidates whose skills include Python, Tableau, or PostgreSQL. The `candidates` table contains `candidate_id` and `skill`.

```sql
SELECT candidate_id
FROM candidates
WHERE skill IN ('Python', 'Tableau', 'PostgreSQL');
```

### 2. Facebook Pages with No Likes

The `pages` table contains `page_id` and `page_name`; `page_likes` contains `user_id`, `page_id`, and `liked_date`. Find pages with no likes.

```sql
SELECT page_id
FROM pages
WHERE page_id NOT IN (SELECT page_id FROM page_likes);
```

### 3. Tesla Unfinished Parts

The `parts_assembly` table contains `part`, `finish_date`, and `assembly_step`. Find parts that have started production but are unfinished, assuming unfinished parts have no `finish_date`.

```sql
SELECT part, assembly_step
FROM parts_assembly
WHERE finish_date IS NULL;
```

### 4. Average Post Hiatus Facebook

For users with at least two posts in 2021, calculate the number of days between their first and last post of that year. The `posts` table contains `user_id`, `post_id`, `post_content`, and `post_date`.

```sql
SELECT
  user_id,
  DATE_PART('day', MAX(post_date) - MIN(post_date)) AS days_between_posts
FROM posts
WHERE EXTRACT(YEAR FROM post_date) = 2021
GROUP BY user_id
HAVING COUNT(*) >= 2;
```

Filter to 2021, group by user, calculate the minimum and maximum post dates, and retain users with at least two posts.

### 5. Microsoft Teams Power Users

From the Microsoft `messages` table (`message_id`, `sender_id`, `receiver_id`, `content`, `sent_date`), find the two users who sent the most messages in August 2022.

```sql
SELECT
  sender_id,
  COUNT(sender_id) AS message_count
FROM messages
WHERE sent_date BETWEEN '08/01/2022' AND '08/31/2022'
GROUP BY sender_id
ORDER BY message_count DESC
LIMIT 2;
```

### 6. LinkedIn Duplicate Job Postings

In `job_listings` (`job_id`, `company_id`, `title`, `description`), a duplicate has the same title and description. Count companies that posted duplicate jobs.

```sql
SELECT COUNT(DISTINCT company_id) AS company_count
FROM (
  SELECT company_id
  FROM job_listings
  GROUP BY company_id, title, description
  HAVING COUNT(*) > 1
) AS duplicates;
```

### 7. Cities With Completed Trades Robinhood

Join Robinhood's `trades` (`order_id`, `user_id`, `quantity`, `status`, `date`, `price`) with `users` (`user_id`, `city`, `email`, `signup_date`) and find the three cities with the most completed orders.

```sql
SELECT
  city,
  COUNT(t.order_id) AS total_orders
FROM trades t
INNER JOIN users u ON t.user_id = u.user_id
WHERE t.status = 'Completed'
GROUP BY u.city
ORDER BY total_orders DESC
LIMIT 3;
```

### 8. Facebook Click-through Rate

For each app in the Facebook `events` table (`app_id`, `event_type`, `timestamp`), calculate 2022 click-through rate to two decimal places.

```sql
SELECT
  app_id,
  ROUND(
    100.0 * COUNT(CASE WHEN event_type = 'click' THEN 1 END)
    / COUNT(CASE WHEN event_type = 'impression' THEN 1 END),
    2
  ) AS ctr
FROM events
WHERE EXTRACT(YEAR FROM timestamp) = 2022
GROUP BY app_id;
```

### 9. Second-Day Confirmation TikTok

Join TikTok's `texts` (`text_id`, `email_id`, `signup_action`, `action_date`) and `emails` (`email_id`, `user_id`, `signup_date`) to find users who confirmed on the second day.

```sql
SELECT user_id
FROM emails e
INNER JOIN texts t ON e.email_id = t.email_id
WHERE t.action_date = e.signup_date + INTERVAL '1 day'
  AND t.signup_action = 'Confirmed';
```

## Intermediate SQL

Intermediate interviews add larger datasets and more complex manipulation. Practice complex joins, nested and correlated subqueries, window functions (`ROW_NUMBER()`, `RANK()`, `DENSE_RANK()`, `LEAD()`, and `LAG()`), `CASE WHEN`, date and time operations, CTEs, set operators (`UNION`, `INTERSECT`, `EXCEPT`), and string functions such as `CONCAT()`, `SUBSTRING()`, and `REPLACE()`.

### 10. Uber Transactions

Return every user's third transaction from `transactions` (`user_id`, `spend`, `transaction_date`).

```sql
SELECT user_id, spend, transaction_date
FROM (
  SELECT
    user_id,
    spend,
    transaction_date,
    ROW_NUMBER() OVER (
      PARTITION BY user_id
      ORDER BY transaction_date
    ) AS rn
  FROM transactions
) AS ranked_transactions
WHERE rn = 3;
```

### 11. Second Highest Salary

Find the second-highest salary in `employee` (`employee_id`, `name`, `salary`, `department_id`, `manager_id`).

```sql
WITH ranked_salaries AS (
  SELECT salary, RANK() OVER (ORDER BY salary DESC) AS rank
  FROM employee
)
SELECT salary
FROM ranked_salaries
WHERE rank = 2;
```

### 12. Snapchat Opening vs. Sending Snaps

Using `activities` (`activity_id`, `user_id`, `activity_type`, `time_spent`, `activity_date`) and `age_breakdown` (`user_id`, `age_bucket`), calculate send and open percentages by age bucket.

```sql
SELECT
  ab.age_bucket,
  ROUND(
    100.0 * SUM(CASE WHEN a.activity_type = 'send' THEN a.time_spent ELSE 0 END)
    / SUM(CASE WHEN a.activity_type IN ('send', 'open') THEN a.time_spent ELSE 0 END),
    2
  ) AS send_perc,
  ROUND(
    100.0 * SUM(CASE WHEN a.activity_type = 'open' THEN a.time_spent ELSE 0 END)
    / SUM(CASE WHEN a.activity_type IN ('send', 'open') THEN a.time_spent ELSE 0 END),
    2
  ) AS open_perc
FROM activities a
JOIN age_breakdown ab ON a.user_id = ab.user_id
WHERE a.activity_type IN ('send', 'open')
GROUP BY ab.age_bucket;
```

### 13. Tweets' Rolling Averages

Calculate each user's three-row rolling average from `tweets` (`user_id`, `tweet_date`, `tweet_count`).

```sql
SELECT
  user_id,
  tweet_date,
  ROUND(
    AVG(tweet_count) OVER (
      PARTITION BY user_id
      ORDER BY tweet_date
      ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
    ),
    2
  ) AS rolling_avg_3d
FROM tweets
ORDER BY user_id, tweet_date;
```

### 14. Amazon Highest-Grossing Items

From `product_spend` (`category`, `product`, `user_id`, `spend`, `transaction_date`), return the two highest-spending products per category in 2022.

```sql
WITH ranking_cte AS (
  SELECT
    category,
    product,
    SUM(spend) AS total_spend,
    RANK() OVER (
      PARTITION BY category
      ORDER BY SUM(spend) DESC
    ) AS rank
  FROM product_spend
  WHERE EXTRACT(YEAR FROM transaction_date) = 2022
  GROUP BY category, product
)
SELECT category, product, total_spend
FROM ranking_cte
WHERE rank <= 2
ORDER BY category, rank;
```

### 15. MAANG Top Three Salaries

Join `employee` and `department` to return the top three salary ranks in each department.

```sql
WITH salary_cte AS (
  SELECT
    d.department_name,
    e.name,
    e.salary,
    DENSE_RANK() OVER (
      PARTITION BY d.department_name
      ORDER BY e.salary DESC
    ) AS rank
  FROM employee e
  INNER JOIN department d ON d.department_id = e.department_id
)
SELECT department_name, name, salary
FROM salary_cte
WHERE rank <= 3;
```

### 16. Spotify Top Five Artists

Using `artists` (`artist_id`, `artist_name`, `label_owner`), `songs` (`song_id`, `artist_id`, `name`), and `global_song_rank` (`day`, `song_id`, `rank`), find the five artists whose songs appear most frequently in the global Top 10.

```sql
WITH songs_cte AS (
  SELECT
    a.artist_name,
    DENSE_RANK() OVER (ORDER BY COUNT(s.song_id) DESC) AS artist_rank
  FROM artists a
  INNER JOIN songs s ON a.artist_id = s.artist_id
  INNER JOIN global_song_rank g ON g.song_id = s.song_id
  WHERE g.rank <= 10
  GROUP BY a.artist_name
)
SELECT artist_name, artist_rank
FROM songs_cte
WHERE artist_rank <= 5;
```

### 17. TikTok Activation Rate

Calculate the confirmed-user activation rate from TikTok's `emails` (`email_id`, `user_id`, `signup_date`) and `texts` (`text_id`, `email_id`, `signup_action`).

```sql
SELECT ROUND(
  COUNT(DISTINCT CASE WHEN t.signup_action = 'Confirmed' THEN e.user_id END) * 1.0
  / COUNT(DISTINCT e.user_id),
  2
) AS confirm_rate
FROM emails e
LEFT JOIN texts t ON e.email_id = t.email_id;
```

### 18. Microsoft Supercloud Customer

Find customers who purchased at least one product from every category using `customer_contracts` (`customer_id`, `product_id`, `amount`) and `products` (`product_id`, `product_category`, `product_name`).

```sql
SELECT cc.customer_id
FROM customer_contracts cc
JOIN products p ON cc.product_id = p.product_id
GROUP BY cc.customer_id
HAVING COUNT(DISTINCT p.product_category) = (
  SELECT COUNT(DISTINCT product_category)
  FROM products
);
```

## Advanced SQL

Senior data engineering interviews may involve very large datasets, data cleaning, synthesis, interpretation, and prediction. Review [Meta data science interview guidance](https://www.aced.io/guides/meta-data-scientist-interview?ref=exponent-blog.ghost.io), [Microsoft guidance](https://www.aced.io/guides/microsoft-data-scientist-interview?ref=exponent-blog.ghost.io), [TikTok guidance](https://www.aced.io/guides/tiktok-data-scientist-interview?ref=exponent-blog.ghost.io), and [Google guidance](https://www.aced.io/guides/google-data-scientist-interview?ref=exponent-blog.ghost.io). Also review [machine learning interview questions](https://www.aced.io/blog/top-machine-learning-interview-questions?ref=exponent-blog.ghost.io).

Key topics include [window functions](https://www.aced.io/courses/sql-interviews/lag?ref=exponent-blog.ghost.io), execution plans, recursive CTEs, [pivot tables](https://www.aced.io/questions/3535/create-function-structured-data-input-output-pivot-table?ref=exponent-blog.ghost.io), transformations and aggregations, transactions (`COMMIT`, `ROLLBACK`, `SAVEPOINT`), normalization, indexing, and schema design.

### 19. Wayfair Year-on-Year Growth Rate

For each product in `user_transactions` (`transaction_id`, `product_id`, `spend`, `transaction_date`), calculate yearly spend, prior-year spend, and year-on-year growth percentage.

```sql
WITH yearly_spend AS (
  SELECT
    EXTRACT(YEAR FROM transaction_date) AS year,
    product_id,
    SUM(spend) AS curr_year_spend
  FROM user_transactions
  GROUP BY year, product_id
), spend_with_prev AS (
  SELECT
    ys1.year,
    ys1.product_id,
    ys1.curr_year_spend,
    LAG(ys1.curr_year_spend) OVER (
      PARTITION BY ys1.product_id
      ORDER BY ys1.year
    ) AS prev_year_spend
  FROM yearly_spend ys1
)
SELECT
  year,
  product_id,
  curr_year_spend,
  prev_year_spend,
  ROUND(
    CASE
      WHEN prev_year_spend IS NULL THEN NULL
      ELSE ((curr_year_spend - prev_year_spend) / prev_year_spend) * 100
    END,
    2
  ) AS yoy_rate
FROM spend_with_prev
ORDER BY product_id, year;
```

### 20. Maximize Amazon Prime Item Inventory

Prioritize Prime-eligible inventory in Amazon's 500,000-square-foot warehouse. `inventory` contains `item_id`, `item_type`, `item_category`, and `square_footage`.

```sql
WITH summary AS (
  SELECT
    item_type,
    SUM(square_footage) AS total_sqft,
    COUNT(*) AS item_count
  FROM inventory
  GROUP BY item_type
), prime_occupied_area AS (
  SELECT
    item_type,
    total_sqft,
    FLOOR(500000 / total_sqft) AS prime_batch_count,
    FLOOR(500000 / total_sqft) * item_count AS prime_item_count
  FROM summary
  WHERE item_type = 'prime_eligible'
)
SELECT
  item_type,
  CASE
    WHEN item_type = 'prime_eligible'
      THEN FLOOR(500000 / total_sqft) * item_count
    WHEN item_type = 'not_prime'
      THEN FLOOR(
        (500000 - (SELECT prime_batch_count * total_sqft FROM prime_occupied_area))
        / total_sqft
      ) * item_count
  END AS item_count
FROM summary
ORDER BY item_type DESC;
```

### 21. Median Google Search Frequency

In `search_frequency` (`searches`, `num_users`), expand each search-frequency row by its user count and calculate the median.

```sql
WITH searches_expanded AS (
  SELECT searches
  FROM search_frequency
  CROSS JOIN GENERATE_SERIES(1, num_users)
)
SELECT ROUND(
  PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY searches)::numeric,
  1
) AS median
FROM searches_expanded;
```

### 22. Facebook Advertiser Status

Use `advertiser` and `daily_pay` to produce updated advertiser statuses. The categories are **New** (new advertiser with a first payment), **Existing** (payment history and a recent additional payment), **Churn** (previous payments but no recent payment), and **Resurrect** (a new payment after a payment gap).

```sql
SELECT
  COALESCE(advertiser.user_id, daily_pay.user_id) AS user_id,
  CASE
    WHEN daily_pay.paid IS NULL THEN 'CHURN'
    WHEN daily_pay.paid IS NOT NULL
      AND advertiser.status IN ('NEW', 'EXISTING', 'RESURRECT') THEN 'EXISTING'
    WHEN daily_pay.paid IS NOT NULL
      AND advertiser.status = 'CHURN' THEN 'RESURRECT'
    WHEN daily_pay.paid IS NOT NULL
      AND advertiser.status IS NULL THEN 'NEW'
  END AS new_status
FROM advertiser
FULL OUTER JOIN daily_pay ON advertiser.user_id = daily_pay.user_id
ORDER BY user_id;
```

### 23. McKinsey 3-Topping Pizzas

Generate every unique three-topping combination from `pizza_toppings` (`topping_name`, `ingredient_cost`), list toppings alphabetically, and sort by total cost descending.

```sql
WITH pizza_combinations AS (
  SELECT
    t1.topping_name AS topping1,
    t2.topping_name AS topping2,
    t3.topping_name AS topping3,
    t1.ingredient_cost AS cost1,
    t2.ingredient_cost AS cost2,
    t3.ingredient_cost AS cost3
  FROM pizza_toppings t1
  JOIN pizza_toppings t2 ON t1.topping_name < t2.topping_name
  JOIN pizza_toppings t3 ON t2.topping_name < t3.topping_name
), pizza_costs AS (
  SELECT
    CONCAT(topping1, ',', topping2, ',', topping3) AS pizza,
    cost1 + cost2 + cost3 AS total_cost
  FROM pizza_combinations
)
SELECT pizza, total_cost
FROM pizza_costs
ORDER BY total_cost DESC, pizza;
```

### 24. MAANG Department vs. Company Salary

Compare each department's average salary with the company's overall average for March 2024 using `employee` and `salary`. Return the department ID, `03-2024`, and `higher`, `lower`, or `same`.

```sql
WITH company_avg AS (
  SELECT AVG(amount) AS avg_salary
  FROM salary
  WHERE EXTRACT(MONTH FROM payment_date) = 3
    AND EXTRACT(YEAR FROM payment_date) = 2024
), department_avg AS (
  SELECT e.department_id, AVG(s.amount) AS avg_salary
  FROM employee e
  JOIN salary s ON e.employee_id = s.employee_id
  WHERE EXTRACT(MONTH FROM s.payment_date) = 3
    AND EXTRACT(YEAR FROM s.payment_date) = 2024
  GROUP BY e.department_id
), comparison AS (
  SELECT
    d.department_id,
    '03-2024' AS payment_date,
    CASE
      WHEN d.avg_salary > c.avg_salary THEN 'higher'
      WHEN d.avg_salary < c.avg_salary THEN 'lower'
      ELSE 'same'
    END AS comparison
  FROM department_avg d
  CROSS JOIN company_avg c
)
SELECT department_id, payment_date, comparison
FROM comparison
ORDER BY department_id;
```

### 25. JPMorgan Chase Card Launch Success

For `monthly_cards_issued` (`issue_month`, `issue_year`, `card_name`, `issued_amount`), return each card's launch-month issuance, where launch means the earliest record for that card.

```sql
WITH ranked_cards AS (
  SELECT
    card_name,
    issue_month,
    issue_year,
    issued_amount,
    ROW_NUMBER() OVER (
      PARTITION BY card_name
      ORDER BY issue_year, issue_month
    ) AS rn
  FROM monthly_cards_issued
)
SELECT card_name, issued_amount
FROM ranked_cards
WHERE rn = 1
ORDER BY issued_amount DESC;
```

## Performance Optimization Queries

### 26. Partial Index on Orders

A partial index covers only rows satisfying a `WHERE` condition. It can reduce index size and improve queries that repeatedly target a subset of a large table.

```sql
CREATE INDEX idx_recent_orders
ON orders (customer_id, order_date)
WHERE order_date >= NOW() - INTERVAL '1 month';
```

This example indexes recent orders rather than every row.

### 27. Analyze JPMorgan Chase Card Launch Success

Use `EXPLAIN ANALYZE` to inspect the execution of question 25.

```sql
EXPLAIN ANALYZE
WITH ranked_cards AS (
  SELECT
    card_name,
    issue_month,
    issue_year,
    issued_amount,
    ROW_NUMBER() OVER (
      PARTITION BY card_name
      ORDER BY issue_year, issue_month
    ) AS rn
  FROM monthly_cards_issued
)
SELECT card_name, issued_amount
FROM ranked_cards
WHERE rn = 1
ORDER BY issued_amount DESC;
```

The supplied execution output includes a quicksort using 25kB, a sequential scan of `monthly_cards_issued_174`, planning time of `0.239 ms`, and execution time of `0.079 ms`. It reports nine scanned rows, two final rows, and seven rows removed by the `rn = 1` filter. The sequential scan is reasonable for the nine-row sample; larger tables may benefit from indexing and further optimization.

### 28. MAANG Department vs. Company Salary Query Optimization

Use range predicates instead of applying `EXTRACT()` to the date column so a database can use a potential index on `payment_date`.

```sql
WITH company_avg AS (
  SELECT AVG(amount) AS avg_salary
  FROM salary
  WHERE payment_date >= '2024-03-01'
    AND payment_date < '2024-04-01'
), department_avg AS (
  SELECT e.department_id, AVG(s.amount) AS avg_salary
  FROM employee e
  JOIN salary s ON e.employee_id = s.employee_id
  WHERE s.payment_date >= '2024-03-01'
    AND s.payment_date < '2024-04-01'
  GROUP BY e.department_id
), comparison AS (
  SELECT
    d.department_id,
    '03-2024' AS payment_date,
    CASE
      WHEN d.avg_salary > c.avg_salary THEN 'higher'
      WHEN d.avg_salary < c.avg_salary THEN 'lower'
      ELSE 'same'
    END AS comparison
  FROM department_avg d
  CROSS JOIN company_avg c
)
SELECT department_id, payment_date, comparison
FROM comparison
ORDER BY department_id;
```

The guide recommends considering indexes on `payment_date`, `employee.employee_id`, and `salary.employee_id`.

## SQL Interview Tips

- Explore our [data engineering course](https://www.aced.io/courses/data-engineering?ref=exponent-blog.ghost.io), which includes mock interviews and practice lessons.
- Schedule a [free mock interview session](https://www.aced.io/practice?ref=exponent-blog.ghost.io).
- Get [data engineer interview coaching](https://www.aced.io/coaching/?ref=exponent-blog.ghost.io).
- Browse [data engineer interview questions](https://www.aced.io/questions?role=data-engineer&src=blog).
- [Book time with a data engineer coach](https://www.aced.io/coaching?role=data-engineer), including mock interviews, career coaching, and resume review.

## Related Aced resources

- [Data Engineering Interview Prep Course](https://www.aced.io/courses/data-engineering): 6 courses and 3,700 students; covers data modeling, pipeline design, SQL, coding, behavioral interviews, and more.
- [Behavioral Interviews: A Practical Guide for Engineers](https://www.aced.io/courses/eng-behavioral): 28 lessons for senior-plus behavioral interviews.
- [Data Scientist vs Data Engineer: Key Differences and Career Insights](https://www.aced.io/blog/data-scientist-vs-data-engineer)
- [Data Engineer Resume Guide (Real Templates)](https://www.aced.io/blog/data-engineering-resume)
- [Ace Your Data Engineering Interview (2026 Guide)](https://www.aced.io/blog/data-engineering-interview)
- [35+ Data Engineer Interview Questions & Answers (2026)](https://www.aced.io/blog/top-data-engineering-interview-questions)

We also provide interview preparation across Product Management, Forward Deployed Engineering, Engineering Management, Software Engineering, System Design, Data Science, Machine Learning, AI Engineering, Investment Banking, Generative AI, Security Engineering, TPM, Solutions Architecture, UX/Product Design, and BizOps & Strategy.

[Create a free Aced account](https://www.aced.io/signup?src=blog).

![Aced Team](https://s3-us-west-2.amazonaws.com/pmlesson/2019/11/exponent-logo-fb.jpg)

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fblog%2Ftop-sql-data-engineering-interview-questions&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fblog%2Ftop-sql-data-engineering-interview-questions). Opening a form does not execute a tool.