Prepin
Log in

Online shopping (1 of 5)

Approach / Explanation

The question suggests that there will be an E-commerce-related problem for you to address using SQL. As it is marked as "1 of 5", it may indicate the beginning of a series of questions based on the same dataset or context. Here are some tips to consider: Since E-commerce typically involves customers, products, orders, payments, and similar entities, you can anticipate these elements to be present in your database and featured in the question. Familiarity with SQL queries, functions, joins, grouping, and ordering will likely be beneficial. Practice executing complex queries that involve multiple joins, as well as integrating aggregate and analytical functions. Learn how to normalize data to enhance data storage efficiency and improve query performance.

Suggested Answer

For example, if you need to identify all products that have never been ordered, you can use an E-commerce database with the tables products and orders , which share the common field prod_id . Your SQL query may resemble the following: SELECT p.prod_name FROM products AS p LEFT JOIN orders AS o ON p.prod_id = o.prod_id WHERE o.prod_id IS NULL; This query effectively begins with the products table and performs a LEFT JOIN with the orders table based on the prod_id column. Following the join, any rows that do not correspond to entries in the orders table will contain NULL values in the orders columns. Therefore, the condition WHERE o.prod_id IS NULL will filter for rows where the product lacks any associated orders.

Alternative Answer

As another illustration, consider the scenario where you need to identify the top-selling products. Let's say you have a products table, an orders table with a shared field prod_id , and a sales table containing order_id and sales_amt fields. Your SQL query might resemble the following: SELECT p.prod_name, SUM(s.sales_amt) AS total_sales FROM products AS p INNER JOIN orders AS o ON p.prod_id = o.prod_id INNER JOIN sales AS s ON o.order_id = s.order_id GROUP BY p.prod_name ORDER BY total_sales DESC LIMIT 10; This query effectively combines the products , orders , and sales tables, groups the results by prod_name , aggregates the sales_amt for each product, and sorts the results in descending order based on total sales. The LIMIT 10 clause restricts the output to the top 10 best-selling products.

Question Details

Difficulty & Category

Medium
sql

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.