In: Computer Science
Assignment Description: In this assignment, a script file should be created to contain a set a SQL statements for the Pretty Prints Company to better manage their business. Use the database created for Pretty Prints in Assignment 2. Include the SQL statements to satisfy the following queries.
The following queries should be included in the script:
a. customer_id is a foreign key in the orders table.
b. Item_id is a foreign key in the orderline table.
HERE IS DATABASE CREATED IN ASSIGNMENT 2:
USE PrettyPrints;
SELECT customer_name, customer_add, customer_city,
customer_state, customer_zip FROM customers;
SELECT customer_name, customer_phone FROM customers WHERE
customer_state = 'GA';
SELECT customer_name, customer_zip FROM customers WHERE
customer_state = 'NC' OR customer_state = 'SC';
SELECT title, artist, order_date, ship_date FROM
items,orders,orderline WHERE orders.order_id = orderline.order_id
AND items.item_id = orderline.item_id;
SELECT * FROM items ORDER BY unit_price ASC;
SELECT * FROM items WHERE unit_price > 100.00;
SELECT * FROM items WHERE on_hand > 300;
SELECT title, unit_price, unit_price * 2 AS retail_price FROM
items;
SELECT title, order_qty FROM items,orderline WHERE items.item_id =
orderline.item_id;
SELECT title FROM items WHERE unit_price BETWEEN 40 AND 100;
Select customer_name, title, artist, sum (order_qty) from customers
left outer join orders on customers.customer_id =
orders.customer_id join orderline on orders.order_id =
orderline.order_id join items on orderline.item_id = items.item_id
group by items.artist order by items.artist;
SELECT c.customer_name, c.customer_phone FROM customers c LEFT OUTER JOIN orders o ON c.customer_id = o.order_id WHERE YEAR(o.ORDER_DATE) = '2014';
SELECT customer_name, sum(unit_price * 2) AS
total_revenue FROM customers join orders on customers.customer_id =
orders.customer_id join orderline on orders.order_id =
orderline.order_id join items on orderline.item_id = items.item_id
group by customer_name;
SELECT customer_state, COUNT(DISTINCT customer_name) AS
number_of_customers FROM customers GROUP BY
customer_state;