0% found this document useful (0 votes)
80 views6 pages

CaseStudy SQL Part3 Allen Joe Winny

case study on sql

Uploaded by

allenjoewinny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views6 pages

CaseStudy SQL Part3 Allen Joe Winny

case study on sql

Uploaded by

allenjoewinny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Allen Joe Winny Spire ID: 34769295

Case Study 3 of 3: SQL with Pine Valley Furniture Company Database


Business Intelligence and Analytics

Your assignment is to write and execute the SQL queries that will produce the data (record sets)
requested below using the Pine Valley Furniture database in Microsoft Access and Teradata SQL
Assistant. Please print out a copy of the Pine Valley Furniture Database Description document
for reference purposes as you work on this assignment.
After you are able to run your SQL statement and get the desired result, copy your

(1) SQL statement (as text), and


(2) the Recordset (your output/results) from each SQL statement

When you have finished, please submit this Word document (with your SQL statements and
output copied into it). You may want to use the “Snipping Tool” to copy the recordset (output).
Submit your Word document through BBLearn.

1. List customer ID, customer name, order ID, order date, product name, and the quantity
multiplied by the price for each product. Give the mathematical expression the alias of
[Extended price].

SELECT
CUSTOMER_t.customer_ID, Customer_Name,ORDER_t.Order_ID,Order_Date,
product_description, Ordered_Quantity*Standard_Price as [Extended price]

From

CUSTOMER_t, ORDER_t, Order_line_t, PRODUCT_t

WHERE

CUSTOMER_t.customer_ID = ORDER_t.customer_ID AND ORDER_t.Order_ID =


Order_line_t.Order_ID AND Order_line_t.Product_ID = PRODUCT_t.Product_ID
;
Hint: You need to include 4 tables in your FROM clause and you need 3 JOINS. You need
to multiply quantity x price.

2. List the order ID, order date, order total, and the total units on each order.

SELECT

ORDER_t.Order_ID,Order_Date, SUM(Ordered_Quantity*Standard_Price) as [Order


Total] , SUM(Ordered_Quantity) as [Total Units]

FROM

ORDER_t, Order_line_t, PRODUCT_t

WHERE

ORDER_t.Order_ID = Order_line_t.Order_ID AND Order_line_t.Product_ID =


PRODUCT_t.Product_ID

GROUP BY

ORDER_t.Order_ID, Order_Date
;

Hint: You need to include 3 tables in your FROM clause and you need 2 JOINS. You need
to SUM the product of quantity x price, and you will need to sum the quantity ordered.

3. How many products in Cherry have been ordered (i.e., the total number of units
ordered)? List the product name, the product finish, and the total quantity ordered for
each product with a Cherry finish. Also give the quantity ordered the alias of “Quantity
Ordered”.

Hint: Use the SUM function with the ordered_quantity field to calculate the number of
products ordered. You will need to use the GROUP BY clause.

SELECT
Product_Description, Product_Finish, SUM(Ordered_Quantity) AS [Total Quantity Ordered]

FROM
Order_line_t, PRODUCT_t

WHERE
Order_line_t.Product_ID = Product_t.Product_ID AND
Product_Finish ='Cherry'

GROUP BY
Product_Description, Product_Finish
;
4. Which product lines have (include) two or less products? Your results should include the
product line name and the number of products included in the product line.

Hint: You will need to use an aggregating function (COUNT) to calculate how many
products are in each product line. Then, you will need to specify criteria that only product
lines with two or less products will be included. Remember that you need to use the SQL
command HAVING to specify criteria for a group (aggregation).

SELECT
Product_Line_Name, Count(*) AS [Number OF Products]

From
PRODUCT_t, PRODUCT_LINE_t

WHERE
PRODUCT_t.Product_Line_ID = PRODUCT_LINE_t.Product_Line_ID

GROUP BY
Product_Line_Name
HAVING
COUNT(*)<=2
;
5. Write a query that will retrieve customer ID, customer name, and order date, and that
will display customer data even if the customer has not placed an order.

SELECT
CUSTOMER_t.Customer_ID,CUSTOMER_t.Customer_Name, Order_Date
FROM
CUSTOMER_t
LEFT JOIN ORDER_t ON CUSTOMER_t.Customer_ID = ORDER_t.Customer_ID
;

Hint: you will need to write an outer join – see pages 164-165 for examples.

6. Write a nested query that will retrieve the product ID, product name, and product price
for each product whose price is greater than the average price of all products.

SELECT
Product_ID,Product_Description,Standard_Price
From
Product_t
Where
Standard_Price > (SELECT AVG(Standard_Price ) FROM Product_t)
;

You might also like