1. The database designer included columns for Year and Month in the Sales_Totals table, but forgot to include a column for Quarter. Write a CASE expression which can be used to return the quarter number (1, 2, 3, or 4) using other column values from the table.

Demonstrate Your Knowledge of Advanced SQL

Prompt: A manufacturing company’s data warehouse contains the following tables.

                                          Region

region_id (p) region_name super_region_id (f)
101 North America
102 USA 101
103 Canada 101
104 USA-Northeast 102
105 USA-Southeast 102
106 USA-West 102
107 Mexico 101

                   

 

 

 

 

 

 

 

 

 

 

 

 

 

                    Product

product_id (p) product_name
1256 Gear – Large
4437 Gear – Small
5567 Crankshaft
7684 Sprocket

 

                                        Sales_Totals

product_id (p)(f) region_id (p)(f) year (p) month (p) sales
1256 104 2020 1 1000
4437 105 2020 2 1200
7684 106 2020 3 800
1256 103 2020 4 2200
4437 107 2020 5 1700
7684 104 2020 6 750
1256 104 2020 7 1100
4437 105 2020 8 1050
7684 106 2020 9 600
1256 103 2020 10 1900
4437 107 2020 11 1500
7684 104 2020 12 900

 

Answer the following questions using the above tables/data:

  1. The database designer included columns for Year and Month in the Sales_Totals table, but forgot to include a column for Quarter.  Write a CASE expression which can be used to return the quarter number (1, 2, 3, or 4) using other column values from the table.
  2. Write a query which will pivot the Sales_Totals data so that there is a column for each of the 4 products containing the total sales across all months of 2020.  It is OK to include the product_id values in your query, and the results should look as follows:

 

tot_sales_large_gears tot_sales_small_gears tot_sales_crankshafts tot_sales_sprockets
6200 5450 0 3050

 

  1. Write a query which retrieves all columns from the Sales_Totals table, along with a column called sales_rank which assigns a ranking to each row based on the value of the Sales column in descending order.
  2. Write a query which retrieves all columns from the Sales_Totals table, along with a column called product_sales_rank which assigns a ranking to each row based on the value of the Sales column in descending order, with a separate set of rankings for each product.
  3. Expand on the query from question #4 by adding logic to return only those rows with a product_sales_rank of 1 or 2.
  4. Write a set of SQL statements which will add a row to the Region table for Europe, and then add a row to the Sales_Total table for the Europe region and the Sprocket product (product_id = 7684) for October 2020, with a sales total of $1,500.  The statements should be executed as a single unit of work.
  5. Write a statement to create a view called Product_Sales_Totals which will group sales data by product and year.  Columns should include product_id, year, product_sales, and gear_sales, which will contain the total sales for the “Gear – Large” and “Gear Small” products (should be generated by an expression, and it is OK to use the product_id values in the expression).
  6. Write a query to return all sales data for 2020, along with a column showing the percentage of sales for each product.  Columns should include product_id, region_id, month, sales, and pct_product_sales.
  7. Write a query to return the year, month, and sales columns, along with a 4th column named prior_month_sales showing the sales from the prior month.  There are only 12 rows in the sales_totals table, one for each month of 2020, so you will not need to group data or filter/partition on region_id or product_id.
  8. If the tables used in this prompt are in the ‘sales’ database, write a query to retrieve the name and type of each of the columns in the Product table.

 

 

TutorPro
Calculate your paper price
Pages (550 words)
Approximate price: -
Tutorpro

High Quality Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level or professional level, and we will assign a writer who has a respective degree.

Tutorpro

Experienced Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Tutorpro

Free Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document.

Tutorpro

Timely Delivery

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension.A 100% refund is guaranteed.

Tutorpro

100% Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text.

Tutorpro

24/7 Customer Services

Tutorpro support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Tutorpro Homework Help Services

At Tutorpro, we have top rated masters and PhD writers who will help you tacke that homework and score A+ grade. Tutorpro services covers all levels of education : high school, college, university undergraduate, masters and PhD academic level.

Essays

Essay Writing

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Tutorpro

Admissions

Admission Essays

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Tutorpro

Editing

Essay Editing

Tutorpro academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Tutorpro

Revision

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. This is free because we want you to be completely satisfied with the service offered.