At LG Electronics, SQL does the heavy lifting for analyzing consumer electronic usage patterns and managing large datasets related to smart home device interconnectivity. That's why LG Electronics almost always evaluates jobseekers on SQL questions during interviews for Data Analytics, Data Science, and Data Engineering jobs.
As such, to help you study for the LG Electronics SQL interview, we've collected 11 LG Electronics SQL interview questions – how many can you solve?
As a data analyst in LG Electronics, you've been tasked with identifying the "whale" customers. These are customers who buy expensive LG products frequently. LG defines a whale customer as one who purchases products worth more than $5,000 at least twice in a month. Write a SQL query to identify these "whale" customers from the customer transactions database.
transaction_id | customer_id | transaction_date | product_id | product_cost |
---|---|---|---|---|
4701 | 426 | 2022-01-04 | 70001 | $6,000.00 |
2802 | 255 | 2022-01-12 | 80052 | $4,000.00 |
3293 | 426 | 2022-01-14 | 90001 | $7,000.00 |
7352 | 426 | 2022-01-26 | 50052 | $5,000.00 |
3517 | 981 | 2022-07-05 | 20052 | $8,000.00 |
The common table expression "whale_identification" is used to store the record of customers who have bought products worth more than $5,000 in a month along with the count of their transactions and the total amount spent. The expression is grouped by customer_id and month_year. Finally, we select all data from this CTE where the count of transactions is 2 or more, i.e. customers who made two or more such purchases in a month.
To practice another SQL customer analytics question where you can solve it right in the browser and have your SQL solution instantly executed, try this Walmart Labs SQL Interview Question:
LG Electronics, being a multinational electronics company, has a wide range of products. The company often collects reviews on these products from customers to understand their performance and customer satisfaction level. You are given a dataset of these reviews, each with a unique review_id, the user_id of the user who provided the review, the date the review was submitted, the product_id of the product that was reviewed, and the number of stars given to the product by the user.
Write a SQL query to calculate the average rating for each product on a monthly basis. The output should be a table that includes the month, product, and the calculated average rating for each product during that month.
review_id | user_id | submit_date | product_id | stars |
---|---|---|---|---|
6171 | 123 | 06/08/2022 | 50001 | 4 |
7802 | 265 | 06/10/2022 | 69852 | 4 |
5293 | 362 | 06/18/2022 | 50001 | 3 |
6352 | 192 | 07/26/2022 | 69852 | 3 |
4517 | 981 | 07/05/2022 | 69852 | 2 |
Your query might look like this in PostgreSQL:
This PostgreSQL query extracts the month from the submit_date column using the EXTRACT function, then groups the reviews by month and product_id. The AVG function is used to calculate the average stars for each combination. Finally, the results are ordered by month and product_id.
To practice another window function question on DataLemur's free interactive SQL code editor, try this Google SQL Interview Question:
The primary key of a table is a column or set of columns that serves as a unique identifier for each row. It ensures that all rows are distinct and does not allow null values.
For example, say you had stored some Facebook ad campaign data that LG Electronics ran:
The column uniquely identifies each row in the table, and the PRIMARY KEY constraint ensures that no two rows have the same . This helps to maintain the integrity of the data in the table by preventing duplicate rows.
The primary key is also an important part of the table because it allows you to easily identify and reference specific campaigns in your Facebook Ad data. You can use it to join to other tables in the database, such as a table containing data on the results of the campaigns.
LG Electronics produces a variety of electronic products like TVs, Mobile phones, Home Appliances, and more. They would like to track the sales performance to understand how their products are doing in different regions in a given period.
product_id | product_name | product_category |
---|---|---|
1 | LG OLED TV | TVs |
2 | LG Refrigerator | Home Appliances |
3 | LG Mobile Phone | Mobiles |
sales_id | product_id | region | sales_date | units_sold |
---|---|---|---|---|
1 | 1 | America | 06/08/2022 | 40 |
2 | 2 | Asia | 06/10/2022 | 25 |
3 | 3 | Europe | 06/18/2022 | 30 |
4 | 2 | America | 06/08/2022 | 50 |
5 | 1 | Europe | 06/08/2022 | 35 |
Write a SQL query that shows the top performing product (in terms of units sold) for each region on a given date.
The query joins the products and sales table on product_id. It then groups the data by region and product name to find the top performing product in each region on date '06/08/2022'. The results are ordered by units sold in descending order to display the top performing product at the top for each region.
The keyword added to a statement can be used to get records without duplicates.
For example, say you had a table of LG Electronics customers:
name | city |
---|---|
Akash | SF |
Brittany | NYC |
Carlos | NYC |
Diego | Seattle |
Eva | SF |
Faye | Seattle |
Suppose you wanted to figure out which cities the customers lived in, but didn't want duplicate results, you could write a query like this:
Your result would be:
city |
---|
SF |
NYC |
Seattle |
For each electronic product sold by LG Electronics, find the average quantity sold per order.
Assume there is an orders table and an order details table with the following data:
order_id | customer_id | order_date |
---|---|---|
1 | 23 | 06/07/2022 |
2 | 17 | 06/10/2022 |
3 | 38 | 06/15/2022 |
4 | 8 | 07/05/2022 |
5 | 68 | 07/19/2022 |
order_id | product_id | quantity |
---|---|---|
1 | 101 | 2 |
1 | 102 | 1 |
2 | 101 | 3 |
2 | 104 | 2 |
3 | 102 | 1 |
4 | 105 | 5 |
5 | 106 | 2 |
We're looking to get the average quantity sold per order for each product.
This query joins the and tables on the column. Then, it groups the resulting records by and calculates the average for each group (i.e., each product). This will give us the average quantity sold per order for each product.
To practice a very similar question try this interactive Amazon Highest-Grossing Items Question which is similar for average sales calculations or this Wayfair Y-on-Y Growth Rate Question which is similar for understanding sales over time.
{#Question-7}
is used to combine the output of multiple statements into one big result!
For a concrete example, say you were a Data Analyst supporting the Sales Analytics team at LG Electronics, and data on potential sales leads lived in both Salesforce CRM and Hubspot. To write a query to analyze leads created after 2023 started, across both CRMs, you could use in the following way:
"
LG Electronics sells a variety of electronic products. Customers may purchase these products and later review them to provide feedback about their experiences. The company tracks all these reviews in a table and wants to derive insights from their customer feedback. They are particularly interested in finding the average rating for each of their products on a monthly basis.
Given a table with the columns , , , , and , write a SQL query that returns the average rating for each product per month. Display the result in the format of . Assume that the is in the format 'MM/DD/YYYY' and that is an integer between 1 and 5.
review_id | user_id | submit_date | product_id | stars |
---|---|---|---|---|
6171 | 123 | 06/08/2022 | 50001 | 4 |
7802 | 265 | 06/10/2022 | 69852 | 4 |
5293 | 362 | 06/18/2022 | 50001 | 3 |
6352 | 192 | 07/26/2022 | 69852 | 3 |
4517 | 981 | 07/05/2022 | 69852 | 2 |
month | product_id | avg_stars |
---|---|---|
6 | 50001 | 3.50 |
6 | 69852 | 4.00 |
7 | 69852 | 2.50 |
This query first uses the function to get the month part from the for each row. It then groups the reviews by the extracted month and and calculates the average by using the function. The part is a type cast to keep only two decimal places in the average ratings.
You are given a customer records database. Your job is to search for all the product records that contain the string 'LG' within the product name from the table.
The table has the following structure and sample data:
product_id | product_name | product_type |
---|---|---|
1001 | Samsung OLED TV | Television |
1002 | LG Ultra HD TV | Television |
1003 | LG Direct Drive Washing Machine | Home Appliance |
1004 | Sony Wi-Fi Speaker | Audio Device |
1005 | LG Inverter Refrigerator | Home Appliance |
Please write a SQL query to filter out and return the products whose name includes 'LG'.
This SQL query uses the operator to match patterns in the column. The symbol is a wildcard that matches any sequence of characters. Therefore, matches any that contains 'LG' anywhere within the string. The result of this SQL query will be the list of products that have 'LG' in the name.
"In SQL, a join generally retrieves rows from multiple tables and combines them into a single result set. For an example of the difference between a left vs. right join, suppose you had a table of LG Electronics orders and LG Electronics customers.
A retrieves all rows from the left table (in this case, the Orders table) and any matching rows from the right table (the Customers table). If there is no match in the right table, NULL values will be returned for the right table's columns.
A combines all rows from the right table (in this case, the Customers table) and any matching rows from the left table (the Orders table). If there is no match in the left table, NULL values will be displayed for the left table's columns.
As a data analyst at LG Electronics, you've been given access to two tables: and . The table contains the customer's ID and name. The table contains information about each purchase such as the customer's ID, product category, purchase date, and purchase amount. Your task is to write a SQL query that calculates the average amount spent by each customer in each product category.
Below are the sample tables:
customer_id | customer_name |
---|---|
1 | John Doe |
2 | Jane Doe |
3 | Peter Parker |
purchase_id | customer_id | product_category | purchase_date | amount_spent |
---|---|---|---|---|
101 | 1 | Electronics | 01/01/2022 | 200 |
102 | 2 | Home Appliances | 02/02/2022 | 500 |
103 | 1 | Electronics | 03/03/2022 | 150 |
104 | 3 | Mobile Devices | 04/04/2022 | 1200 |
105 | 1 | Mobile Devices | 05/05/2022 | 1800 |
This query first joins the (c) table with the (p) table using the field that is common to both tables. Once joined, the function is used to calculate the average amount spent () by each customer ('customer_name') in each product category (). The 'GROUP BY' clause ensures the average is calculated for each unique combination of customer and product category.
Because joins come up so often during SQL interviews, try this interactive Snapchat SQL Interview question using JOINS:
Assuming that you've already got basic SQL skills, the next best tip we have to prepare for the LG Electronics SQL interview is to solve as many practice SQL interview questions as you can! Beyond just solving the earlier LG Electronics SQL interview questions, you should also solve the 200+ SQL exercises on DataLemur which come from companies like Google, Microsoft and Silicon Valley startups.
Each DataLemur SQL question has multiple hints, full answers and most importantly, there is 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 LG Electronics SQL interview it is also useful to practice SQL questions from other tech companies like:
But if your SQL foundations are weak, forget about jumping right into solving questions – improve your SQL foundations with this free SQL for Data Analytics course.
This tutorial covers SQL topics like Subqueries and rank window functions – both of these come up frequently during LG Electronics SQL interviews.
Beyond writing SQL queries, the other question categories to practice for the LG Electronics Data Science Interview are:
The best way to prepare for LG Electronics Data Science interviews is by reading Ace the Data Science Interview. The book's got: