Question

In: Computer Science

Task 6.2.1. For each publisher with more than $2000 in purchase orders, list the customer id,...

Task 6.2.1. For each publisher with more than $2000 in purchase orders, list the customer id, name, credit code, and total of the orders. Use a WHERE clause to perform the join across the five required tables.

DROP TABLE publishers;
DROP TABLE po_items;
DROP TABLE bookjobs;
DROP TABLE items;
DROP TABLE pos;

CREATE TABLE publishers (
cust_id CHAR(3) NOT NULL,
name CHAR(10),
city CHAR(10),
phone CHAR(8),
creditcode CHAR(1),
PRIMARY KEY (cust_id)
);

CREATE TABLE bookjobs (
job_id CHAR(3) NOT NULL,
cust_id CHAR(3),
job_date DATE,
descr CHAR(10),
jobtype CHAR(1),
PRIMARY KEY (job_id),
FOREIGN KEY (cust_id) REFERENCES publishers (cust_id)
);

CREATE TABLE pos (
job_id CHAR(3) NOT NULL,
po_id CHAR(3) NOT NULL,
po_date DATE,
vendor_id CHAR(3),
PRIMARY KEY (job_id, po_id),
FOREIGN KEY (job_id) REFERENCES bookjobs (job_id)
);

CREATE TABLE items (
item_id CHAR(3) NOT NULL,
descr CHAR(10),
on_hand SMALLINT,
price DECIMAL(5,2),
PRIMARY KEY (item_id)
);

CREATE TABLE po_items (
job_id       CHAR(3) NOT NULL,
po_id       CHAR(3) NOT NULL,
item_id       CHAR(3) NOT NULL,
quantity     SMALLINT,
FOREIGN KEY (job_id) REFERENCES bookjobs (job_id),
FOREIGN KEY (job_id, po_id) REFERENCES pos (job_id, po_id),
FOREIGN KEY (item_id) REFERENCES items (item_id)
);

Solutions

Expert Solution

WHERE clause to perform the join across the five required tables.

SELECT

             customers.cust_fname, orders.order_id, orders.order_date

FROM

             customers INNER JOIN orders

             ON customer.cust_id = orders.cust_id;

Result:

cust_name

order_id

order_date

ABC Co.

123456

2005-06-20

ABC Co.

147893

2006-12-14

...

...

...

XYZ Ltd.

258963

2010-05-06

Interestingly, you can also write an inner join SQL query using WHERE clause to have the same effect as follows.

SELECT

             customers.cust_fname, orders.order_id, orders.order_date

FROM

             customers, orders

WHERE

             customers.cust_id = orders.cust_id;

In this case the join is done implicitly by the database optimizers. This type of query though functionally equivalent is highly discouraged due to its misleading nature as a simple SELECT query.

The INNER JOIN is the default join operation in MySQL databases; therefore, the keyword INNER is optional.

SELECT 
             customers.cust_fname, orders.order_id, orders.order_date 
FROM 
             customers LEFT OUTER JOIN orders 
ON customer.cust_id = orders.cust_id;
SELECT 
             customers.cust_fname, orders.order_id, orders.order_date 
FROM 
             customers RIGHT OUTER JOIN orders 
ON customer.cust_id = orders.cust_id;
SELECT 
             customers.cust_fname, customers.cust_lname
FROM 
             customers
 
UNION
 
SELECT 
             employees.emp_fname, employees.emp_lname
FROM 
             employees

Related Solutions

How many customers purchased more than 1 product? (Hint: Customer ID stays the same per customer...
How many customers purchased more than 1 product? (Hint: Customer ID stays the same per customer when he/she buys several food boxes) Please Tell me the steps on how this would be solved using Excel. Note that this is not the full excel data but just a small sample. date_sign_up customer_id product_name marketing_channel City 4/17/2015 13:11 71041 Classic - 3 meals per week for 2 people Search Engine Marketing San Diego 4/14/2015 11:32 103289 Classic - 3 meals per week...
A publisher is interested in the effects on sales of college texts that include more than...
A publisher is interested in the effects on sales of college texts that include more than 100 data files. The publisher plans to produce 20 texts in the business area and randomly choses 10 to have more than 100 data files. The remaining 10 are produced with at most 100 data files. For those with more than 100, first-year sales averaged 9254, and the sample standard deviation was 2107. For the books with at most 100, average first-year sales were...
Create a java program with class Customer: Name, Surname, ID (incremental ID by 1 for each...
Create a java program with class Customer: Name, Surname, ID (incremental ID by 1 for each new customer), Email, Phone, Address. The program must create New customer, and Print information for customer with a certain ID.   
A newsletter publisher believes that more than 24% of their readers own a personal computer. Is...
A newsletter publisher believes that more than 24% of their readers own a personal computer. Is there sufficient evidence at the 0.10 level to substantiate the publisher's claim? State the null and alternative hypotheses for the above scenario.
Publisher is interested in the effects of sales of college texts that include more than 100...
Publisher is interested in the effects of sales of college texts that include more than 100 data files. The Publisher plans to produce 20 texts in the business area and randomly chooses 10 to have more than 100 fileas. The remaining 10 are produced with at most 100 files. For those with mıre than 100, first-year sales averaged 9254 and the sampel standard deviation was 2107. Fort he boks with at most 100 files, average first-year sales were 8167, and...
List customer id, customer full name (Last name, full name, state) for those customers that have...
List customer id, customer full name (Last name, full name, state) for those customers that have ordered more than once. List customers (order id, customer id, and customer last name) that had more than 2 -- products in their order. Order your result based on customer id followed by order id SQL SERVER DATABASE
The forecast for each week is 50 units each week and customer orders are as shown...
The forecast for each week is 50 units each week and customer orders are as shown in the table below. The beginning inventory level is 0 and the production lot size is 75. Determine Available-to-promise inventory under the condition that “schedule production when the projected on-hand inventory would be negative without production”. June    July 1 2 3 4 1 2 3 4 Forecast 50 50 50 50 50 50 50 50 Customer order (committed) 52 35 20 12
List the appropriate post hoc test (or tests if more than one is suitable) for each...
List the appropriate post hoc test (or tests if more than one is suitable) for each scenario described: Weight gained by students dining at three different cafeterias over a six-month period Weight loss by students attending four different campus gym locations over a three-month period Planned comparisons of pre-med students’ average organic chemistry test scores across four different colleges, one of which is a state school, while the others are private schools Sleep quality measured in minutes, by students using...
Assumption: 1. The acquisition cost for each new customer is $35. 2. Each customer will purchase...
Assumption: 1. The acquisition cost for each new customer is $35. 2. Each customer will purchase five times a year. For each purchase, the profit value is $8. 3. Retention rate (r) is 80% and Interest rate (i) is 4.5%. Questions: Note: Please round up all answers to the nearest tenth (two digits after the decimal point). (1) Please fill out the empty cells in the table below. And write down all the detailed calculation steps. (2) In order to...
List the players that have either won more than 2 matches or lost more than 2...
List the players that have either won more than 2 matches or lost more than 2 matches. List the player number, name, initials, won, and lost. Insert your snip here. Which players are captains of a team and have ever served as a committee members? Display the player number, player name, initials, team number, and committee member position. This will require 3 tables. Insert your snip here. Using a subquery, have any other players been penalized the same amount as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT