Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views1 page

Amazon Interview Question

The document provides SQL queries to analyze product reviews and sales data. It includes a table structure for ProductReviews and Orders, along with sample data and queries to calculate average review ratings by month and determine top-selling products based on total order amounts. The queries utilize GROUP BY and aggregate functions to summarize the data effectively.

Uploaded by

haaryysmith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Amazon Interview Question

The document provides SQL queries to analyze product reviews and sales data. It includes a table structure for ProductReviews and Orders, along with sample data and queries to calculate average review ratings by month and determine top-selling products based on total order amounts. The queries utilize GROUP BY and aggregate functions to summarize the data effectively.

Uploaded by

haaryysmith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

AMAZON INTERVIEW QUESTION

1. SQL Query to Calculate Average Review Ratings.


Suppose you need to analyze customer feedback for products over time and you have a
below table Reviews containing review_id, product_id,
user_id, rating and review_date. Your task is to calculate the average review
ratings for each product every month.

CREATE TABLE ProductReviews (


review_id INT PRIMARY KEY,
product_id INT,
user_id INT,
rating INT,
review_date DATE
);
INSERT INTO ProductReviews (review_id, product_id, user_id, rating, review_date)
VALUES
(1, 101, 201, 4, '2024-01-10'),
(2, 102, 202, 5, '2024-01-15'),
(3, 101, 203, 3, '2024-02-10'),
(4, 103, 201, 4, '2024-02-20'),
(5, 101, 204, 5, '2024-02-25');

A) select *from ProductReviews


select product_id,year(review_date) as years ,month(review_date) as
months ,avg(rating) as avg_rating from productreviews
group by product_id,year(review_date) ,month(review_date) order by product_id
-----------------------------------------------------------------------------------
----------------------------------------
2. Determining Top-Selling Products Based on Analyzing Sales Data for Profitable
Insights?

CREATE TABLE Orders (


order_id INT PRIMARY KEY,
product_id INT,
order_amount DECIMAL(10, 2)
);
INSERT INTO Orders (order_id, product_id, order_amount)
VALUES
(1, 101, 50.00), (2, 102, 75.00), (3, 101, 100.00), (4, 103, 120.00), (5, 101,
80.00), (6, 102, 90.00),
(7, 101, 110.00),(8, 103, 130.00), (9, 102, 85.00),(10, 101, 95.00), (11, 102,
70.00),(12, 103, 140.00);
A) select product_id,sum(order_amount) as top_selling_product from Orders group by
product_id

You might also like