Answered step by step
Verified Expert Solution
Link Copied!

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

);

  1. Consider the product schema (given above) to answer the following questions.

  1. Write a SQL query which retrieves product it and total quantity of bestselling product (i.e., largest quantity product) in each year.

  1. Write a SQL query which retrieves three highest and three lowest price products in the sales table.

  1. 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

  1. 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

  1. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

=+What is the procedure for labor relations in the workplace?

Answered: 1 week ago

Question

=+ Are ballots compulsory?

Answered: 1 week ago