Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CREATE TABLE SALES ( SALE_ID INTEGER, PRODUCT_ID INTEGER, YEAR INTEGER, QUANTITY INTEGER, PRICE INTEGER ); Consider the product schema (given above) to answer the following
CREATE TABLE SALES
(
SALE_ID INTEGER,
PRODUCT_ID INTEGER,
YEAR INTEGER,
QUANTITY INTEGER,
PRICE INTEGER
);
- Consider the product schema (given above) to answer the following questions.
- Write a SQL query which retrieves product it and total quantity of bestselling product (i.e., largest quantity product) in each year.
- Write a SQL query which retrieves three highest and three lowest price products in the sales table.
- Write a SQL query using the analytic function to find the total sales of each product? Sample outcome of the SQL statement is given below.
PRODUCT_ID QUANTITY TOT_SALES
----------------------------------------------------------
100 12 22
100 10 22
200 15 25
200 10 25
- Write a SQL query to find the cumulative sum of sales(QUANTITY) of each product? Sample outcome of the SQL statement is given below.
PRODUCT_ID QUANTITY CUM_SALES
----------------------------------------------------------
100 8 8
100 10 18
100 12 30
200 10 10
200 13 23
200 14 37
- Write a SQL query to find the sum of sales of current row and previous 2 rows in a product group? Sample outcome of the SQL statement is given below.
PRODUCT_ID QUANTITY CALC_SALES
------------------------------------------------------------
100 25 25
100 16 41
100 12 53
200 20 20
200 15 35
200 14 49
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started