Question

SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f)...

SQL

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

Note: (p) = "primary key" and (f) = "foreign key". They are not part of the column names.

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:

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

6. 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. You can assign any value to the region_id column, as long as it is unique to the Region table. The statements should be executed as a single unit of work. Please note that since the statements are executed as a single unit of work, additional code is needed.

Homework Answers

Answer #1

Answer :

2 ) SELECT [Gear - Large] as tot_sales_large_gears,[Gear - Small] as tot_sales_small_gears,[Crankshaft] as tot_sales_crankshafts,[Sprocket] as tot_sales_sprockets FROM   
(select P.product_name,ISNULL(ST.sales,0)as sales from Sales_Totals ST join Product P on ST.product_id=P.product_id)t
PIVOT(SUM(sales)
FOR product_name IN (
[Gear - Large] ,
[Gear - Small],
[Crankshaft],
[Sprocket])
) AS pivot_table;

Result :

tot_sales_large_gears
tot_sales_small_gears

tot_sales_crankshafts

tot_sales_sprockets
6200 5450 NULL 3050

========================================================================================

ANSWERED AS PER MY KNOWLEDGE

IF ANY DOUBTS COMMENT IT

THANKYOU

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Apply the classification algorithm to the following set of data records. The class attribute is Gender....
Apply the classification algorithm to the following set of data records. The class attribute is Gender. RID Age City Gender Education Repeat Customer 101 20..30 NY F College YES 102 20..30 SF M Graduate YES 103 31..40 NY F College    YES 104 51..30 NY F College NO 105 31..40 LA M High school    NO 106 41..50 NYY F College YES 107 41..50 NY F Graduate    YES 108 20..30 LA M College    YES 109 20..30 NY F...
*******please don't copy and paste and don't use handwriting **** Q1: Using the below given ASCII...
*******please don't copy and paste and don't use handwriting **** Q1: Using the below given ASCII table (lowercase letters) convert the sentence “welcome to cci college” into binary values. a - 97 b - 98 c - 99 d - 100 e - 101 f - 102 g - 103 h - 104 i - 105 j - 106 k - 107 l - 108 m - 109 n - 110 o - 111 p - 112 q - 113...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE TABLE Student (  sid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  address VARCHAR(20) NOT NULL,  major CHAR(2)); CREATE TABLE Professor (  pid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  department VARCHAR(10) NOT NULL); CREATE TABLE Course (  cid INT PRIMARY KEY,  title VARCHAR(20) NOT NULL UNIQUE,  credits INT NOT NULL,  area VARCHAR(5) NOT NULL); CREATE TABLE Transcript (  sid INT,  cid INT,  pid INT,  semester VARCHAR(9),  year YEAR,  grade CHAR(1) NOT NULL,  PRIMARY KEY (sid, cid, semester, year),  FOREIGN KEY (sid) REFERENCES Student...
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch08_ConstructCo database are shown in Figure P8.1. Use this database to answer the following problems. Database Schema The schema for the Ch08_ConstructCo database is shown below and should be used to answer the next several problems. Click this image to view it in its own...
SQL Write the queries necessary to obtain the required information 1) Use sub query and “in”...
SQL Write the queries necessary to obtain the required information 1) Use sub query and “in” keyword to print the salesreps (ids) who have taken order for the companies ‘Zetacorp’ or ‘JCP Inc.’ . Duplicate rows are not allowed 2) Use sub query to find the id and the name of every sales rep that represents at least one customer with a credit limit of greater than $5000. 3) Use sub query and keyword “exists” to list the id and...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following tables: VENDOR, PRODUCT, CUSTOMER, INVOICE, LINE EMPLOYEE and loads the default data rows */ set echo on; set serveroutput on; select systimestamp from dual; show user; ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'; DROP TABLE LINE CASCADE CONSTRAINTS; DROP TABLE INVOICE CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE VENDOR CASCADE CONSTRAINTS; DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; CREATE TABLE...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following tables: VENDOR, PRODUCT, CUSTOMER, INVOICE, LINE EMPLOYEE and loads the default data rows */ set echo on; set serveroutput on; select systimestamp from dual; show user; ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'; DROP TABLE LINE CASCADE CONSTRAINTS; DROP TABLE INVOICE CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE VENDOR CASCADE CONSTRAINTS; DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; CREATE TABLE...
Bivariate Data & Probability After completing the calculation by hand in Q1 you can use Excel...
Bivariate Data & Probability After completing the calculation by hand in Q1 you can use Excel to check your answers before submitting. Q2 assesses your general understanding of probability and linear associations using Excel to analyse a large dataset. Question 1       Covariance and Correlation The table below shows a set of sample bivariate data. Calculate the covariance and correlation coefficient by completing the below table. Show all working. X Y (X - ) (Y - ) (X - )(Y -...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT