logo

9 Delivery Hero SQL Interview Questions (Updated 2024)

Updated on

March 1, 2024

At Delivery Hero, SQL is used quite frequently for analyzing customer order patterns and underlies their Data Mesh Platform. That's why Delivery Hero almost always evaluates jobseekers on SQL coding questions in interviews for Data Analytics, Data Science, and Data Engineering jobs.

So, to help you ace the Delivery Hero SQL interview, this blog covers 9 Delivery Hero SQL interview questions – able to answer them all?

9 Delivery Hero SQL Interview Questions

SQL Question 1: Identify Top Customers for Delivery Hero

Delivery Hero is a leading global online food delivery platform. Assume you have a 'orders' table which tracks every order made by customers. The higher the number of orders from a customer, the more valuable the customer is to the business.

Your task here is to write a SQL query that can identify the top 5 customers who made the highest number of orders in the last 30 days.

Consider the below as the full data in the 'orders' table:

Example Input:

Answer:


This PostgreSQL query works as follows - It filters out orders which have been made in the last 30 days using the WHERE clause. It then groups these orders by customer_id and counts the number of orders made by each customer. It finally sorts these customers in descending order of order_count to get the customers with the highest number of orders and limits the output to the top five customers.

To work on a similar customer analytics SQL question where you can solve it interactively and have your SQL code instantly graded, try this Walmart SQL Interview Question: Walmart Labs SQL Interview Question

SQL Question 2: Calculate Monthly Average Delivery Times

Delivery Hero would obviously be interested in tracking delivery times for their orders. As an interviewee, you might be asked to write a SQL query to analyze the average delivery time on a monthly basis using a window function.

Consider the following hypothetical datasets:

Example Input:
order_idcustomer_idrestaurant_idorder_placedorder_delivered
110042001/01/2022 12:00:0001/01/2022 12:30:00
210114202/01/2022 13:00:0002/01/2022 13:40:00
310264202/01/2022 18:00:0002/01/2022 18:45:00
410342003/01/2022 11:00:0003/01/2022 11:35:00
510442003/01/2022 20:00:0003/01/2022 20:25:00

In this dataset, and are both timestamps.

Your task is to calculate the average delivery time for orders each month. The delivery time for an order can be calculated by subtracting the timestamp from the timestamp.

Answer:

The PostgreSQL query for this might look like the following,


In this query, is used to group orders by month. The function is used to calculate the time difference between when the and in seconds, and then we divide by 60 to get the time in minutes. This is then averaged with the SQL function.

To practice a related window function SQL problem on DataLemur's free interactive coding environment, solve this Google SQL Interview Question: Google SQL Interview Question

SQL Question 3: Can you explain the concept of a constraint in SQL?

Constraints are just rules for your DBMS to follow when updating/inserting/deleting data.

Say you had a table of Delivery Hero employees, and their salaries, job titles, and performance review data. Here's some examples of SQL constraints you could implement:

NOT NULL: This constraint could be used to ensure that certain columns in the employee table, such as the employee's first and last name, cannot contain NULL values.

UNIQUE: This constraint could be used to ensure that the employee ID is unique. This would prevent duplicate entries in the employee table.

PRIMARY KEY: This constraint could be used to combine the NOT NULL and UNIQUE constraints to create a primary key for the employee table. The employee ID could serve as the primary key.

FOREIGN KEY: This constraint could be used to establish relationships between the employee table and other tables in the database. For example, you could use a foreign key to link the employee ID to the department ID in a department table to track which department each employee belongs to.

CHECK: This constraint could be used to ensure that certain data meets specific conditions. For example, you could use a CHECK constraint to ensure that salary values are always positive numbers.

DEFAULT: This constraint could be used to specify default values for certain columns. For example, you could use a DEFAULT constraint to set the employee hire date to the current date if no value is provided when a new employee is added to the database.

Delivery Hero SQL Interview Questions

SQL Question 4: Analyzing Delivery Performance

Delivery Hero is interested in understanding the efficiency and timeliness of their deliveries. Specifically, they would like to know which cities achieve the fastest delivery times on average. As an Database Analyst, you are tasked to design a relational database and write an SQL query to find out average delivery time for each city.

Assume the datamodel contains two tables - and .

Table:

order_iddelivery_idcity_idorder_timedelivery_time
1001200112023-02-01 09:30:002023-02-01 10:00:00
1002200222023-02-01 09:45:002023-02-01 10:30:00
1003200312023-02-01 10:00:002023-02-01 10:45:00
1004200432023-02-01 11:00:002023-02-01 11:40:00
1005200532023-02-01 11:15:002023-02-01 11:50:00

Table:

city_idcity_name
1Berlin
2Hamburg
3Munich

Answer:

The PostgreSQL query to get the average delivery time for each city is as follows:


EXPLAINATION:

The query joins and tables on . For each city, it calculates the time difference between and , converts it into minutes (using ), then calculates the average of these time differences. The result is sorted by in ascending order to show the cities with the fastest average delivery times at the top.

SQL Question 5: What does do?

The function is used to remove NULLs, and replace them with another value.

For example, say you were a Data Analyst at Delivery Hero and were doing a customer analytics project to see who the most marketing-engaged customers were, and had access to the below table.

delivery_hero_customers:

customer_idemail_engagementsms_engagement
101very_activenot_opted_in
201un-subscribedNULL
301NULLnot_opted_in
401not_activevery_active
501very_activemildly_active
303NULLNULL

Before you could procede, you had to remove the NULLs, and replace them with the default value (not_active for email, and not_opted_in for SMS). To do this, you'd run the following query:


This would get you the following output:

customer_idemail_engagementsms_engagement
101very_activenot_opted_in
201un-subscribednot_opted_in
301not_activenot_opted_in
401not_activevery_active
501very_activemildly_active
303not_activenot_opted_in

SQL Question 6: Filter Customers For Specific Delivery Requirements

As a Delivery Hero data analyst, your task is to identify customers that meet a specific set of delivery requirements.

Specifically, you need to filter out customers who have:

  1. Placed more than 3 orders in the last 30 days.
  2. Specifically ordered pizza in their last order.
  3. Are based in Berlin, Germany.

The data is scattered across three tables: customers, orders, and order_items.

The table contains customer information:

customer_idnamecitycountry
1JohnBerlinGermany
2SarahParisFrance
3MarkBerlinGermany
4LucyLondonUK

The table records customer orders:

order_idcustomer_idorder_date
10112022-09-01
10222022-09-02
10332022-09-03
10412022-09-04
10512022-09-05

And the table contains individual items of each order:

order_item_idorder_idproduct
1001101Pizza
1002102Burger
1003103Pizza
1004104Pizza
1005105Pizza

Answer:

Here is a sample PostgreSQL query you could write to solve this problem:


This query first joins the three tables together. It makes sure that the city is Berlin and the country is Germany and selects only those records for which the order date is within the last 30 days and the product is Pizza. It groups by customer_id and name and gets only those records where the count of distinct order_id is greater than 3.

This query helps pipeline the customers that meet Delivery Hero's specific criteria, helping the company make data-driven decisions.

SQL Question 7: What is denormalization?

Denormalization is the practice of altering a database schema in a way that breaks the normalization rules (1NF, 2NF, 3NF, etc.).

This is typically done to improve the performance of the database when it is being used for online analytics processing (OLAP), rather than online transaction processing (OLTP) use cases.

Denormalization can improve query performance by reducing the number of expensive joins required to retrieve data, but it comes with it's own drawbacks too. By adding redundant columns, you incur more data storage costs, and there's need for more complex update and delete operations in order to maintain data integrity across all the duplicated data. Thus, it's important to carefully consider the trade-offs involved before implementing denormalization.

SQL Question 8: Find Customers In Berlin

Delivery Hero is interested in targeting marketing to customers who live in Berlin. From the table, find all customers who have a city name that contains the word 'Berlin'.

Example Input:
customer_idfirst_namelast_nameemailaddresscity
9834JohnDoejohn.doe@email.com123 Anonymous StBerlin-Pankow
5643JaneSmithjane.smith@email.com456 Anonymous AveBerlin-Mitte
3465FrankWhitefrank.white@email.com789 Anonymous BlvNew York
7489JakeGreenjake.green@email.com234 Anonymous wayLondon
Example Output:
customer_idfirst_namelast_nameemailaddresscity
9834JohnDoejohn.doe@email.com123 Anonymous StBerlin-Pankow
5643JaneSmithjane.smith@email.com456 Anonymous AveBerlin-Mitte

Answer:


This SQL query will retrieve all customer records from the table where the field contains the string 'berlin' (case insensitive). The LIKE keyword in SQL allows us to use wildcards ('%') in our string comparisons, enabling us to match portions of a string. Here, we've enclosed 'berlin' in '%', which will match any string that contains 'berlin', at any position. Using the LOWER function ensures that the match is case-insensitive, so it will correctly match 'Berlin', 'BERLIN', 'berlin', etc.

SQL Question 9: Calculate Monthly Discounts and Round-off for Each Product

Consider the and tables of the Delivery Hero database. The table contains records of all transactions and the table includes the list of all products, their prices, and their IDs. Assume that at some point a product can be sold at a discount.

Write a SQL query that can:

  1. Calculate the total discounts accrued on each product for each month
  2. Calculate the sqrt of the total amount of each product sold
  3. Round the discount and the total amount to the nearest whole number
  4. Exclude records where the discount was not provided or was zero.
Example Input:
sale_idsale_dateproduct_idquantitysale_price
100108/01/2021 00:00:00200052600
100208/15/2021 00:00:00200131800
100308/30/2021 00:00:00200021200
100409/05/2021 00:00:0020011700
100509/10/2021 00:00:00200063300
Example Input:
product_idproduct_price
2000650
2001750

Answer:


This solution calculates the total discount for each month and for each product by subtracting the sale price from the product price (for each unit sold), then sums it up for all units sold. Then, it calculates the sqrt of total_sale and rounds it to the nearest whole number. The resulting rows are filtered to exclude products where the discount was not given or zero.

The two most similar questions to "Calculate Monthly Discounts and Round-off for Each Product" are "Y-on-Y Growth Rate" and "Average Review Ratings".

  • The "Y-on-Y Growth Rate" question involves dealing with transactions and calculation of growth rates. This relates to the part of the original question where you need to calculate discounts.

  • The "Average Review Ratings" problem involves calculating averages grouped by month, which mirrors the monthly calculations in your question.

Here is the markdown output based on these findings:

To practice a very similar question try this interactive Wayfair Y-on-Y Growth Rate Question which is similar for calculating transaction values or this Amazon Average Review Ratings Question which is similar for monthly calculations.

Delivery Hero SQL Interview Tips

The best way to prepare for a SQL interview, besides making sure you have strong SQL fundamentals, is to practice a ton of real SQL questions that were asked in recent job interviews. Beyond just solving the above Delivery Hero SQL interview questions, you should also solve the 200+ SQL exercises on DataLemur which come from companies like Google, Microsoft and Silicon Valley startups. DataLemur SQL Interview Questions

Each exercise has hints to guide you, detailed solutions and best of all, there is an interactive SQL code editor so you can right in the browser run your query and have it checked.

To prep for the Delivery Hero SQL interview you can also be useful to solve SQL problems from other tech companies like:

But if your SQL coding skills are weak, forget about diving straight into solving questions – improve your SQL foundations with this SQL tutorial for Data Analytics.

SQL tutorial for Data Scientists & Analysts

This tutorial covers SQL concepts such as advantages of CTEs vs. subqueries and WHERE vs. HAVING – both of which show up routinely in Delivery Hero SQL assessments.

Delivery Hero Data Science Interview Tips

What Do Delivery Hero Data Science Interviews Cover?

Beyond writing SQL queries, the other topics covered in the Delivery Hero Data Science Interview are:

  • Probability & Stats Questions
  • Coding Questions in Python or R
  • Product Analytics Questions
  • ML Interview Questions
  • Resume-Based Behavioral Questions

Delivery Hero Data Scientist

How To Prepare for Delivery Hero Data Science Interviews?

The best way to prepare for Delivery Hero Data Science interviews is by reading Ace the Data Science Interview. The book's got:

  • 201 Interview Questions from Google, Microsoft & tech startups
  • A Crash Course covering Python, SQL & ML
  • Amazing Reviews (900+ reviews, 4.5-star rating)

Ace the DS Interview