8 Meituan SQL Interview Questions (Updated 2024)

Updated on

February 6, 2024

At Meituan, MySQL & TiDB by PingCap is used day-to-day for analyzing user behavior patterns for tailored recommendations and managing large data sets to optimize delivery logistics. Unsurprisingly this is why Meituan often tests SQL problems during interviews for Data Science, Data Engineering and Data Analytics jobs.

So, if you're stressed about an upcoming SQL Assessment, we've curated 8 Meituan SQL interview questions – how many can you solve?

8 Meituan SQL Interview Questions

SQL Question 1: Power Users on Meituan

Question:

Assume that Meituan is a food delivery platform. It has a table that records each order placed by its users. Power users are defined as users who place orders four or more times a week. Write a SQL query to identify these power users for the current week.

Example Input:

Order_idUser_idRestaurant_idOrder_dateOrder_amount
1012230707/18/2022 13:00:0019.99
1023352807/19/2022 07:00:0010.09
1032277907/20/2022 20:00:0030.99
1044430707/21/2022 17:30:0045.00
1052252807/22/2022 12:45:0025.90
1063377907/22/2022 18:15:0033.79
1072230707/23/2022 13:30:0020.50
1085552807/23/2022 07:00:0012.89

Answer:

The following PostgreSQL query would solve this problem:


Explanation:

This query does the following:

  1. Filters the records from the current week: .
  2. Groups the records by : .
  3. Aggregates the data by the count of orders per user: .
  4. Only keeps the users who placed an order 4 or more times: .

The result is the list of user IDs corresponding to power users. Note that 'Order' in the clause is an example table name and should be replaced with the actual order data table name in Meituan's database.

To practice a related customer analytics question on DataLemur's free interactive SQL code editor, try this Microsoft SQL Interview problem: Microsoft SQL Interview Question: Super Cloud Customer

SQL Question 2: Analyze Product's Monthly Average Rating

Meituan, just like any other product based company, relies on customer's reviews of their products. Analysing these reviews can provide important insights about how well the products are received. In this SQL question, you are asked to write a query that can calculate the monthly average rating (stars) for each product.

Let's consider as the dataset which includes following fields: , , , and . Here, is an unique identifier for each review, identifies unique customers who submitted the review, is the date when the review was submitted, represents unique products and indicates the rating given by the customer ranging from 1 to 5.

Example Input:
review_iduser_idsubmit_dateproduct_idstars
61711232022-06-08 00:00:00500014
78022652022-06-10 00:00:00698524
52933622022-06-18 00:00:00500013
63521922022-07-26 00:00:00698523
45179812022-07-05 00:00:00698522

We want to generate a result with the following structure where is the month of the year (e.g., 1 for January, 2 for February, etc.), represents unique products and is the average rating for that product in that particular month.

Example Output:
mthproductavg_stars
6500013.5
6698524.0
7698522.5

Answer:

A SQL solution using window functions and my be written in this way:


This query works by first extracting the month from the using the function. Then it averages the for each for each month using the function. The clause with is used to window the data by and month. Finally, the resulting table is sorted by month and product, to present the data in an organized manner.

To solve a related window function SQL problem on DataLemur's free online SQL coding environment, solve this Amazon SQL Interview Question: Amazon Business Intelligence SQL Question

SQL Question 3: What do stored procedures do, and when would you use one?

Stored procedures are a lot like functions in programming. They're used to encapsulate and organize business logic into one unit of code, and they can accept multiple input parameters and return multiple output values.

For example, if you were a Data Analyst at Meituan working on a HR analytics project, you might create a stored procedure to calculate the average salary for a given department:


To call this stored procedure and find the average salary for the Data Analytics department you'd write the following query:


Meituan SQL Interview Questions

SQL Question 4: Finding Customers Ordering Specific Meal Type

Meituan is a large delivery and on-demand food services business. Your task is to use the table to find out how many customers ordered 'Vegetarian' meal option in the year 2021.

Example Input:
order_idcustomer_idorder_datemeal_typerestaurant_id
25510872021-03-07Vegetarian707
67329982021-12-04Meat Lover550
47826572020-05-25Vegetarian707
58239002021-10-18Fish Feast356
31923202021-11-14Vegetarian707

Answer:


This query uses the SQL command to find the number of unique customers, the clause to filter the where is 'Vegetarian' and where the order was placed in the year 2021. A special date function is used to get the year part from the . undefined

SQL Question 5: Can you explain the purpose of the SQL constraint?

A UNIQUE constraint ensures that all values in a column are different. It is often used in conjunction with other constraints, such as NOT NULL, to ensure that the data meets certain conditions.

For example, if you had Meituan employee data stored in a database, here's some constraints you'd use:


In the Meituan employee example, the UNIQUE constraint is applied to the "email" field to ensure that each employee has a unique email address. This helps to ensure the integrity of the data in the database and prevents errors that could occur if two employees had the same email address.

SQL Question 6: Analysing transaction and customer data

In Meituan, we maintain two tables, and . The has the fields , , , and .

The includes , and .

Your task is to write a SQL query to join these two tables and find the total amount each customer has spent on a given restaurant. Assume the restaurant_id for the given restaurant is 'R101'.

Here's an example of how you should format sample tables:

Example Input:
transaction_idcustomer_idorder_amounttransaction_daterestaurant_id
101C110008/01/2022R101
102C215008/01/2022R102
103C120008/02/2022R101
104C35008/02/2022R101
105C17508/03/2022R103
Example Input:
customer_idcustomer_namecity
C1John DoeBeijing
C2Jane SmithShanghai
C3Mary JohnsonBeijing

Examples of Output:

Example Output:
customer_nametotal_amount_spent
John Doe300
Mary Johnson50

Answer:


This query first joins the table and table on . It then filters for transactions where is 'R101'. The function is used to get the total per customer and is used to group the result by .

Since joins come up frequently during SQL interviews, try this interactive Snapchat Join SQL question: Snapchat SQL Interview question using JOINS

SQL Question 7: Can you explain the distinction between an inner and a full outer join?

An inner join returns only the rows that match the join condition between the two tables, whereas a full outer join returns all rows from both tables, including any unmatched rows.

Example:


Example:


SQL Question 8: Average Daily Sales for a Specific Product Category

Meituan, as a multinational tech company specializing in local services, has extensive service categories. Let's focus on the "Food Delivery" category. Interviewees are provided the and tables. The table stores all sales and their timestamp. The table contains the details of all the products sold in the "Food Delivery" category.

The question is: Write a SQL query to calculate the average daily sales (in terms of the quantity sold) for the "Burger" product type in the "Food Delivery" category for the month of August 2022.

Example Input:
order_idproduct_idquantityorder_timestamp
1092567308/01/2022 00:30:22
2389891208/03/2022 10:15:50
3490567108/03/2022 09:25:35
4874245408/04/2022 14:15:13
5218891308/10/2022 18:39:56
Example Input:
product_idproduct_typecategory
567BurgerFood Delivery
891BurgerFood Delivery
245PizzaFood Delivery
786NoodlesFood Delivery

Answer:


The above PostgreSQL query first joins the and tables on the column. It then filters out orders of "Burger" type in the "Food Delivery" category and in the month of August 2022. The postgres function truncates the timestamp to the day level and the month level, respectively. The result is grouped by the date, and the average sale quantity is calculated daily. The clause sorts the result by date. undefined

How To Prepare for the Meituan SQL Interview

The key to acing a Meituan SQL interview is to practice, practice, and then practice some more! Besides solving the above Meituan SQL interview questions, you should also solve the 200+ SQL Interview Questions on DataLemur which come from companies like Google, Microsoft and Silicon Valley startups. DataLemur SQL Interview Questions

Each problem on DataLemur has hints to guide you, detailed solutions and crucially, there's an interactive SQL code editor so you can right in the browser run your query and have it graded.

To prep for the Meituan SQL interview it is also wise to solve SQL problems from other tech companies like:

In case your SQL foundations are weak, forget about diving straight into solving questions – refresh your SQL knowledge with this DataLemur SQL Tutorial.

SQL tutorial for Data Scientists & Analysts

This tutorial covers topics including UNION and Self-Joins – both of which come up often in Meituan SQL assessments.

Meituan Data Science Interview Tips

What Do Meituan Data Science Interviews Cover?

For the Meituan Data Science Interview, besides SQL questions, the other types of questions which are covered:

  • Statistics and Probability Questions
  • Python or R Programming Questions
  • Data Case Study Questions
  • Machine Learning and Predictive Modeling Questions
  • Behavioral Based Interview Questions

Meituan Data Scientist

How To Prepare for Meituan Data Science Interviews?

To prepare for Meituan Data Science interviews read the book Ace the Data Science Interview because it's got:

  • 201 interview questions sourced from Facebook, Google & startups
  • a crash course covering Stats, ML, & Data Case Studies
  • over 900+ reviews on Amazon & 4.5-star rating

Acing Data Science Interview

© 2024 DataLemur, Inc

Career Resources

Free 9-Day Data Interview Crash CourseFree SQL Tutorial for Data AnalyticsUltimate SQL Interview GuideAce the Data Job Hunt Video CourseAce the Data Science InterviewBest Books for Data Analysts