10 Lenovo SQL Interview Questions (Updated 2024)

Updated on

March 1, 2024

At Lenovo, SQL is used analyzing product usage data for insights on customer behavior, and managing inventory databases to optimize supply chain processes. Because of this, Lenovo almost always asks SQL problems in interviews for Data Analytics, Data Science, and Data Engineering jobs.

To help you practice for the Lenovo SQL interview, this blog covers 10 Lenovo SQL interview questions – how many can you solve?

10 Lenovo SQL Interview Questions

SQL Question 1: Calculate Average Product Rating

Assume that you are working as a Data Analyst for Lenovo and you need to discover how well different products are being rated by the customers. Write a PostgreSQL query to calculate the average rating () per month for each product ().

Order the result by month () and then by product ().

Please consider the table for your SQL query:

Example Input:
617112306/08/2022 00:00:00500014
780226506/10/2022 00:00:00698524
529336206/18/2022 00:00:00500013
635219207/26/2022 00:00:00698525
451798107/05/2022 00:00:00698524

Expected output:

Example Output:


Here is a sample PostgreSQL query that uses the window function to solve this problem:

This query extracts the month from the column, and calculates the average of over each per month. It then orders the result set by month and product. In the output, represents the month of the , represents the , and represents the average for each product per month. The clause in the window function is used to calculate the average for each group of and month.

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

SQL Question 2: Lenovo Product Sales Analysis

Lenovo, a multinational technology company, needs to analyse their monthly sales. They are particularly interested in determining the total quantity of each product sold and the total sales amount each month.

Consider you are provided with two tables, and . The table lists all the products along with their price, and the table logs all sales transactions mentioning the date of sale, quantity, and the product sold.

Example Input
50001Lenovo Laptop A700
50002Lenovo Laptop B800
50003Lenovo Phone A500
Example Input

Write a SQL query to generate a report that displays the year, month, total quantity of each product sold during that month, and the total sales amount for each product per month.

Expected Output


In the above query, we join the and tables using the as the common column. We then use the function to get the year and the month from the column in the table. The function is used to calculate the total quantity sold and the total sales for each product per month. Finally, we use to arrange the data by year, month, and . The clause sorts the final output by year, month, and in decreasing order of total sales.

SQL Question 3: What is the difference between a primary key and a foreign key?

To clarify the distinction between a primary key and a foreign key, let's examine employee data from Lenovo's HR database:


+------------+------------+------------+------------+ | employee_id| first_name | last_name | manager_id | +------------+------------+------------+------------+ | 1 | Aubrey | Graham | 3 | | 2 | Marshal | Mathers | 3 | | 3 | Dwayne | Carter | 4 | | 4 | Shawn | Carter | | +------------+------------+------------+------------+

In this table, serves as the primary key. It uniquely identifies each employee and cannot be null.

functions as a foreign key, linking to the of the employee's manager. This establishes a relationship between Lenovo employees and their managers, allowing for easy querying to find an employee's manager or see which employees report to a specific manager.

The table may also have multiple foreign keys that reference primary keys in other tables. For example, and foreign keys could be used to connect each employee to their respective department and location.

Lenovo SQL Interview Questions

SQL Question 4: Filter Lenovo Customers Based on Business Values

Lenovo would like to segment their customer database to focus on their marketing efforts. They specifically want to filter the customers who are over the age of 25, have purchased a laptop within the last year, and are living in the United States. Additionally, if a customer has opted out of marketing communications, they should not be included in this segment, regardless of other criteria.

Customer and purchase information are stored in separate tables, and .

Table Example Input:
Table Example Input:


To answer this question, a combination of SQL commands and concepts will be used such as JOIN to combine the two tables, WHERE to filter the records, AND and OR to combine multiple conditions, as well as comparison operators to compare the values.

The PostgreSQL query for the problem would be:

The query returns the customer IDs of customers who are over the age of 25, who purchased a laptop within the last year, and who live in the US, assuming that they have opted in for marketing communications. The JOIN allows us to connect the customers' information with their purchase records, and the WHERE clause helps us filter out the customers meeting Lenovo's criteria. For the purchase date, we check against the current date minus one year to make sure we get people who bought a laptop in the last year.

SQL Question 5: How is the constraint used in a database?

A is a field in a table that references the of another table. It creates a link between the two tables and ensures that the data in the field is valid.

Say for example you had sales analytics data from Lenovo's CRM (customer-relationship management) tool.

In this example, the table has a foreign key field called that references the "account_id" field in the table (the primary key). This helps to link the data about each opportunity to the corresponding account information in the accounts table.

This makes sure the insertion of rows in the table that do not have corresponding entries in the table. It also helps to enforce the relationship between the two tables and ensures that data is not deleted from the table if there are still references to it in the table.

SQL Question 6: Average Sales Price of Lenovo Laptops for Each Month

As a data analyst at Lenovo, you are asked to track the average sales price of Lenovo laptops for each month. Given a sales data containing laptop id, selling date and selling price, write a SQL query to find out the average sales price for each month.

Example Input:

Example Output:


This SQL query first extracts the month from the "sale_date" column using the EXTRACT function. Then it groups the sales records by month and calculates the average sales price for each group using the AVG aggregate function. The resulting output is sorted by month in ascending order.

To practice a very similar question try this interactive Wayfair Y-on-Y Growth Rate Question which is similar for tracking sales over time or this Amazon Average Review Ratings Question which is similar for calculating monthly averages.

SQL Question 7: What's denormalization, and when does it make sense to do it?

Denormalization is the practice of altering a database schema in a way that breaks the normalization rules (1st, 2nd, 3rd normal forms).

A few reasons to denormalize a database:

  • Improved performance: Denormalization often reduces the the number of costly join operations that are needed to retrieve data. This is helpful when the database is being used for OLAP (Online Analytical Processing) use cases at Lenovo, as joins can be expensive and slow.

  • Scalability: Denormalization can be like a turbo boost for your database's scalability! By requiring less data to be read and processed when executing a query, denormalization can help your database handle a ton of queries without breaking a sweat.

  • Simplification: One way to simplify the design of a database is by using denormalization to reduce the number of tables and relationships that need to be managed. This can make the database easier to understand and maintain.

Of course, don't over-do the database denormalization magic – too much redundancy can increase data storage costs, and get complicated to manage if there's frequent commands that need to be run.

SQL Question 8: Determine Click-Through-Rate For Lenovo Ads

For Lenovo, a global leader in the tech market, understanding the effectiveness of their online advertising efforts is paramount. Your task is to calculate the click-through rate (CTR) for Lenovo's digital ads within a given period.

The CTR is the ratio of users who click on a specific link to the total number of users who view the ad (also known as impressions).

You have access to two data tables:

Example Input:
Example Input:


Here is the PostgreSQL query that you can use to calculate the CTR:

This query first joins the impressions and clicks tables on ad and user id, then counts the amount of impressions and clicks for each ad id. In the outer query, it calculates the CTR by using the counts of clicks and impressions.

To practice a related problem on DataLemur's free online SQL code editor, attempt this SQL interview question asked by Facebook: Facebook App CTR SQL Interview question

SQL Question 9: Filtering Customer records for specific pattern

You've been given a database of Lenovo's customers. The company wants to implement a customer-focused marketing strategy and hence need to filter the customer database to target customers who have a Microsoft email (i.e., their email addresses end with 'microsoft.com').

For example, consider the following customers' table:

Example Input:
1John Doejdoe@microsoft.com
2Jane Smithjsmith@gmail.com
3Peter Griffinpgriffin@microsoft.com
4Lois Griffinlgriffin@yahoo.com
5Stewie Griffinsgriffin@microsoft.com

You are supposed to get a table with the below structure and content:

Example Output:
1John Doejdoe@microsoft.com
3Peter Griffinpgriffin@microsoft.com
5Stewie Griffinsgriffin@microsoft.com

Write a SQL query to filter customers records matching these conditions.


If you are working with a database such as PostgreSQL, a SQL query using could be used to solve this problem.

This query uses the keyword in SQL, and the percent sign as a wildcard character to denote zero, one, or multiple characters. Therefore, this query will return any entries in the table where the field ends with . The resulting set will only include customers with a Microsoft email address.

SQL Question 10: What does the SQL keyword do?

The clause is used to remove all duplicate records from a query.

For example, if you had a table of open jobs Lenovo was hiring for, and wanted to see what are all the unique job titles that were currently available at the company, you could write the following query:

How To Prepare for the Lenovo SQL Interview

Assuming that you've already got basic SQL skills, the next best tip we have to prepare for the Lenovo SQL interview is to solve as many practice SQL interview questions as you can! Beyond just solving the above Lenovo SQL interview questions, you should also solve the 200+ DataLemur SQL Interview Questions which come from companies like Netflix, Google, and Amazon. DataLemur SQL and Data Science Interview Questions

Each interview question has multiple hints, step-by-step solutions and best of all, there's an online SQL code editor so you can right in the browser run your SQL query answer and have it checked.

To prep for the Lenovo SQL interview it is also wise to practice interview questions from other tech companies like:

In case your SQL query skills are weak, don't worry about going right into solving questions – refresh your SQL knowledge with this free SQL tutorial.

Free SQL tutorial

This tutorial covers things like creating summary stats with GROUP BY and joining a table to itself – both of these come up routinely during SQL job interviews at Lenovo.

Lenovo Data Science Interview Tips

What Do Lenovo Data Science Interviews Cover?

In addition to SQL query questions, the other types of questions to prepare for the Lenovo Data Science Interview are:

Lenovo Data Scientist

How To Prepare for Lenovo Data Science Interviews?

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

  • 201 Interview Questions from companies like Microsoft, Google & Amazon
  • A Crash Course on Python, SQL & ML
  • Amazing Reviews (900+ 5-star reviews on Amazon)

Ace the DS Interview