+ All Categories
Home > Documents > €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 [email protected] 4 Paul...

€¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 [email protected] 4 Paul...

Date post: 24-Jun-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
47
Spooner Berry Farm Group 1: Nick Birge Olivia Walker Pierce Fleming Rito Karashima BMIS 441-01 1
Transcript
Page 1: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

Spooner Berry Farm

Group 1:Nick Birge

Olivia WalkerPierce FlemingRito KarashimaBMIS 441-01

TABLE OF CONTENTS:

1

Page 2: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

I. PROJECT Scenario…..…………………………………………………………………………3II. PROJECT OBJECTIVES……………………………………………………………………...3III. SYSTEMS DEVELOPMENT LIFE CYCLE (SDLC).............................................................4 1. ANALYSIS………………………………………………………………………….….4 2. DESIGN ER-D………………………………………………………………………………5 ORDER OF ENTERING DATA………………………………………………….5

NORMALIZATIONS...………………………………………………………...6-7 3. IMPLEMENTATION TABLE CREATION AND INSERTION………………………………………....7 FUNCTIONAL QUERIES………………………………………………………14 4. POST-IMPLEMENTATION MANAGERIAL AND ORGANIZATIONAL IMPACTS………………………17 MAINTENANCE………………………………………………………………..17 GROWTH AND CHANGE……………………………………………………...17IV. CONCLUSION……………………………………………………………………………....17V. SPOOLED SCRIPT FILES 1. Table Insertion……………………………..……………………………………...…..19 2. Functional Query Outputs.………………..………………………………….…….….32VI. POWERPOINT SLIDES…………………………………………………………………….38

2

Page 3: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

Spooner Berry FarmProject's description (scenario):

Spooner Berry Farms is a medium size berry farm located in Olympia Washington. They sell berries throughout Western Washington from as far North as Seattle all the way down to Centralia. Spooner Berry Farms is famous for their raw unpasteurized honey as well as their sweet berries. Their goal is to “provide the freshest berries possible” so they pick fresh berries depending on customer needs and orders. They pick seven days a week in order to make this goal become reality. Due to this aspect, they could benefit from a database system that better keeps track of customers and inventory in order to ensure that their mission stays the same as they continue to grow to more customers and areas.

In business since 1982, Spooner Berry Farm's data is still all on paper. This is the main reason a database system would be very useful because there isn't any form of one currently. Since there is this lack of a central system, Spooner Berry Farm could benefit with the use of technology. With the implementation of a database, they will be able to track historical averages of certain dates and weather reports to calculate the amount of berries that should be picked for each day. This will help them make their business more efficient and lean. Being for efficient in tracking customers and other elements will allow this family owned farm to continue to grow.

Objectives (what you try to accomplish):

1. The primary objective of this database is to move all previous data from paper to a database so that it is easy to access and manage. This will make it easy for Spooner Berry Farms to access and analyze their data.

2. By storing certain forms of data, Spooner Berry Farms will also be able to track certain metrics to they can optimize their business. The metrics that Spooner Berry Farms could track are sales, inventory, and customers/.

3. Spooner Berry Farms could also use the database to analyze and project where the business is now and where it it heading.

Once Spooner Berry Farms has all of their data in a digital format, they will be able to make analyze their data using computer tools which will allow them to make their processes more efficient. This is important because with Spooner Berry Farm's data all on paper, it is very difficult to visualize and act upon it. Being able to visualize and analyze different data points will make it easy to act on historical data to make the farm more profitable.

SDLC

3

Page 4: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

Now that we have recognized the problems Spooner Berry Farm faces and determined that a database system would be feasible and useful, we are looking into exactly how to reach our objectives.

Analysis:Things to track:

● Customers● Locations (11 locations)● Berry seasons & supply● Employees● Fixed costs

Tracking all these things will allow Spooner Berry Farms to make informed business decision they need to optimize their business whereas with everything on paper is extremely difficult to make informed business decisions. With the database system, they will be able to look into every element of their farm and stay organized in order to become more productive. This will allow us to operationalize our main objective creating a simple and useful system for all the data needed to be more efficient for Spooner Berry Farms.

In order to reach the objectives, we will create a database with all the necessary elements like listed above. For example, with the supply, this focuses on our objective on managing inventory in order to better satisfy customers. Since there are 12 locations, it would be easier for them to have a central system in order to limit inconsistencies. With a normalized system, there will now be a lack of data redundancy or other anomalies that has been taking place simply by using paper for so many different aspects. With our database, they will be able to easily access their inventory which will allow for better productivity and customer satisfaction.

Additionally, for the objective of analyzing their business currently opening Spooner Berry Farms up for growth a database would greatly help. They could put current and historical data into the system to be able to better analyze their past records and customers. This way all customer information is stored so they can easily look up buying habits and contact information, for example. .

ER-D

4

Page 5: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

5

Page 6: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

6

Page 7: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

7

Page 8: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

TABLE CREATION, INSERTION, and VIEWS:-- Oracle SQL, Term Project Phase III-- BMIS441-01-- GROUP 1-- Spooner Berry Farm

SET LINESIZE 150SET PAGESIZE 45

DROP TABLE Delivery CASCADE CONSTRAINTS;DROP TABLE Employee CASCADE CONSTRAINTS;DROP TABLE EmployeeType CASCADE CONSTRAINTS;DROP TABLE Location CASCADE CONSTRAINTS;DROP TABLE OrderItem CASCADE CONSTRAINTS;DROP TABLE Product CASCADE CONSTRAINTS;DROP TABLE Orders CASCADE CONSTRAINTS;DROP TABLE Customer CASCADE CONSTRAINTS;

--Creating tables and inserting data

CREATE TABLE CUSTOMER(CustomerID NUMBER(4),C_Name VARCHAR(23),C_Address NUMBER(5),C_Street VARCHAR(20),C_City VARCHAR(20),C_State CHAR(2),C_Zip NUMBER(5),C_Email VARCHAR(40),CONSTRAINT customer_customerid_pk PRIMARY KEY (CustomerID));

INSERT INTO CustomerVALUES(0001, 'Bill Gates', 1835, '73rd Ave', 'Medina', 'WA', 98039, '[email protected]');

INSERT INTO CustomerVALUES(0002, 'Jeff Bezos', 2093, 'Evergreen Point Rd', 'Medina', 'WA', 98039, '[email protected]');

INSERT INTO Customer

8

Page 9: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

VALUES(0003, 'Howard Schultz', 1500, 'E 42nd Ave', 'Seattle', 'WA', 98112, '[email protected]');

INSERT INTO CustomerVALUES(0004, 'Paul Allen', 6555, 'W Mercer Way', 'Mercer Island', 'WA', 98040, '[email protected]');

INSERT INTO CustomerVALUES(0005, 'Steve Ballmer', 3832, 'Hunts Point Rd', 'Hunts Point', 'WA', 98004, '[email protected]');

INSERT INTO CustomerVALUES(0006, 'Pierce Fleming', 1122, 'River Road', 'Spokane', 'WA', 98202, '[email protected]');

CREATE TABLE ORDERS(OrderID NUMBER(4),CustomerID NUMBER(4),PaymentType VARCHAR2(10),Satisfaction NUMBER(1),CONSTRAINT ORDERS_OrderID_pk PRIMARY KEY (OrderID),CONSTRAINT ORDERS_CustomerID_fk FOREIGN KEY (CustomerID)References CUSTOMER (customerID));

INSERT INTO ORDERSVALUES(1001, 0004, 'Credit', 3 );

INSERT INTO ORDERSVALUES(1002, 0005, 'Cash', 4);

INSERT INTO ORDERSVALUES(1003, 0001, 'Credit', 2);

INSERT INTO ORDERSVALUES(1004, 0005, 'Debit', 3);

INSERT INTO ORDERSVALUES(1005, 0003, 'Cash', 2 );

INSERT INTO ORDERSVALUES(1006, 0002, 'Debit', 4);

9

Page 10: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

INSERT INTO ORDERSVALUES(1007, 0004, 'Debit', 5);

CREATE TABLE PRODUCT(BerryType VARCHAR(15),Cost NUMBER(4),Retail NUMBER(4),CONSTRAINT product_berrytype_pk PRIMARY KEY (BerryType));

INSERT INTO ProductVALUES('Raspberry', 2.00, 4.00);

INSERT INTO ProductVALUES('Blueberry', 1.50, 3.00);

INSERT INTO ProductVALUES('Strawberry', 2.50, 5.00);

INSERT INTO ProductVALUES('Blackberry', 2.00, 5.00);

INSERT INTO ProductVALUES('Marionberry', 1.00, 2.00);

CREATE TABLE ORDERITEM(OrderID NUMBER(4),BerryType VARCHAR(15),Quantity NUMBER(3),CONSTRAINT ORDERITEM_OrderID_pk PRIMARY KEY (OrderID,BerryType),CONSTRAINT ORDERITEM_OrderID_fk FOREIGN KEY (OrderID)References ORDERS (OrderID),CONSTRAINT ORDERITEM_BerryType_fk FOREIGN KEY (BerryType)References PRODUCT (BerryType));

INSERT INTO ORDERITEMVALUES(1001,'Raspberry', 5);

INSERT INTO ORDERITEMVALUES(1002,'Blackberry', 7);

10

Page 11: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

INSERT INTO ORDERITEMVALUES(1002,'Strawberry', 7);

INSERT INTO ORDERITEMVALUES(1003,'Blueberry’, 6);

INSERT INTO ORDERITEMVALUES(1004,'Strawberry', 4);

INSERT INTO ORDERITEMVALUES(1005,'Strawberry', 3);

INSERT INTO ORDERITEMVALUES(1005,'Blackberry', 4);

INSERT INTO ORDERITEMVALUES(1006,'Marionberry',6);

INSERT INTO ORDERITEMVALUES(1007,'Strawberry', 4);

CREATE TABLE LOCATION(locationID NUMBER(3), L_Name VARCHAR(20), L_Street VARCHAR2(50), L_City VARCHAR2(10), L_State CHAR(2), L_Zip NUMBER(5), CONSTRAINT location_locationid_pk PRIMARY KEY (locationID));

INSERT INTO LocationVALUES(001, 'Tumwater','5200 Capital Blvd', 'Tumwater', 'WA', 98501);

INSERT INTO LocationVALUES(002, 'Olympia', 'Ralph''s Thriftway 1908 4th Ave E', 'Olympia', 'WA', 98506);

INSERT INTO Location VALUES(003, 'Aberdeen', '1213 East Wishkah Street', 'Aberdeen', 'WA', 9820);

11

Page 12: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

INSERT INTO Location VALUES(004, 'Shelton', '1826 Olympic Hwy N. ', 'Shelton', 'WA', 98584);

INSERT INTO Location VALUES(005, 'Centralia', '1215 Harrison', 'Centralia', 'WA', 98531);

INSERT INTO Location VALUES(006, 'Westside of Olympia','2010 Harrison Ave NW', 'Olympia', 'WA', 98502);

INSERT INTO Location VALUES(007, 'North Seattle', '7726 35th Ave NE', 'Seattle', 'WA', 98115);

INSERT INTO Location VALUES(008, 'Yelm', '1109 E. Yelm Ave', 'Yelm', 'WA', 98597);

INSERT INTO Location VALUES(009, 'Farm', '3327 Yelm Hwy', 'Olympia', 'WA', 98513);

INSERT INTO Location VALUES(010, 'Farmers Market','700 Capitol Way', 'Olympia', 'WA', 98501);

INSERT INTO Location VALUES(011, 'Hawks Prairie','1200 Marvin Rd NE', 'Lacey', 'WA', 98516);

CREATE TABLE EMPLOYEETYPE(TypeID NUMBER(3), Description VARCHAR2(20), CONSTRAINT employeetype_typeid_pk PRIMARY KEY (typeID));

INSERT INTO EmployeetypeVALUES(001, 'Manager');

INSERT INTO EmployeetypeVALUES(002, 'Berry Picker');

INSERT INTO EmployeetypeVALUES(003, 'Casher');

INSERT INTO EmployeetypeVALUES(004, 'Driver');

12

Page 13: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

CREATE TABLE Employee(EmployeeID NUMBER(3),E_Name VARCHAR(23),LocationID NUMBER(3),TypeID NUMBER(3),Date_Employed DATE,HourlyPay NUMBER(3),CONSTRAINT Employee_EmployeeID_pk PRIMARY KEY (EmployeeID),CONSTRAINT Employee_LocationID_fk FOREIGN KEY (LocationID)References Location (LocationID),CONSTRAINT Employee_TypeID_fk FOREIGN KEY (TypeID)References EmployeeType (TypeID));

INSERT INTO EmployeeVALUES(101, 'Sue Spooner',009,001,'10-JUN-1985', 17);

INSERT INTO EmployeeValues(102, 'Tim Spooner',009,001,'10-AUG-1985', 17);

INSERT INTO EmployeeValues(103, 'Megan Birge',010,003, '20-JUN-2008', 14.5);

INSERT INTO EmployeeValues(104, 'Nick Birge', 005,003, '07-JUN-2013', 13.5);

INSERT INTO EmployeeValues(105, 'Cobi Beal', 006, 003, '02-JUN-2016', 11.5);

INSERT INTO EmployeeValues(106, 'Taylor Bellamy', 001, 003, '05-JUN-2016', 11.5);

INSERT INTO EmployeeValues(107, 'George Smith', 001, 004, '07-JUN- 2014', 13.0);

INSERT INTO EmployeeValues(108, 'Tyler Parks', 009, 002, '10-JUN-2007', 14.5);

INSERT INTO EmployeeValues(109, 'Stan Lee', 009, 002, '04-JUN-1998', 15);

13

Page 14: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

INSERT INTO EmployeeValues(110, 'Gary Tillman', 003, 003, '07-JUN-2005', 15.0);

INSERT INTO EmployeeValues(111, 'Jill White', 004, 003, '28-MAY-2010', 14.0);INSERT INTO EmployeeValues (112, 'Joe Jackson', 007, 004, '03-JUN-2015', 13.0);

INSERT INTO EmployeeValues (113, 'Macey Cobb', 008, 004, '13-JUN-2016', 12.5);

CREATE TABLE Delivery(DeliveryID NUMBER(3),EmployeeID NUMBER(3),LocationID NUMBER(3),Quantity NUMBER(3),DeliveryCost NUMBER(4),CONSTRAINT Delivery_DeliveryID_pk PRIMARY KEY (DeliveryID),CONSTRAINT Delivery_EmployeeID_fk FOREIGN KEY (EmployeeID)References Employee (EmployeeID),CONSTRAINT Delivery_LocationID_fk FOREIGN KEY (LocationID)References Location (LocationID)); INSERT INTO DeliveryValues (201, 107, 001, 150, 10); INSERT INTO DeliveryValues (202, 112, 007, 200, 30); INSERT INTO DeliveryValues (203, 113, 008, 85, 15);

--Creating Views

CREATE OR REPLACE VIEW customer_satisfaction_view(CustomerID, C_Name, OrderID, satisfaction)AS SELECT c.customerid, c.c_name, o.orderid, o.satisfactionFROM customer c, orders oWHERE c.customerid = o.customerid

14

Page 15: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

ORDER BY c.c_name;

SELECT * FROM customer_satisfaction_view;

CREATE OR REPLACE VIEW order_charge_view(customerid, c_name, orderid, charge)AS SELECT c.customerid, c.c_name, o.orderid, (oi.quantity * p.retail)FROM customer c, orders o, orderitem oi, product pWHERE c.customerid = o.customeridAND o.orderid = oi.orderidAND oi.berrytype = p.berrytypeORDER BY c.c_name;

SELECT * FROM order_charge_view;

CREATE OR REPLACE VIEW order_cost_view(customerid, c_name, orderid, cost)AS SELECT c.customerid, c.c_name, o.orderid, (oi.quantity * p.cost)FROM customer c, orders o, orderitem oi, product pWHERE c.customerid = o.customeridAND o.orderid = oi.orderidAND oi.berrytype = p.berrytypeORDER BY c.c_name;

SELECT * FROM order_cost_view;

FUNCTIONAL QUERIES:

--#1 Which customers have a satisfaction rating lower or equal to 3? SELECT cv.C_Name, cv.Satisfaction, c.C_EmailFROM customer_satisfaction_view cv, CUSTOMER cWHERE cv.C_Name = c.C_Name

15

Page 16: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

AND Satisfaction <= 3;

--#2 How much did each order in total charge the customers? Select orderid, customerID, c_name, SUM(charge) "total charge"From order_charge_viewGroup By orderid, customerID, c_name;

--#3 Who has purchased the same berry type as Steve Ballmer?CREATE OR REPLACE VIEW order_type_view (c_name, BerryType)AS SELECT c.C_Name, oi.BerryTypeFROM CUSTOMER c, ORDERS o, ORDERITEM oiWHERE oi.OrderID=o.OrderIDAND o.CustomerID=c.CustomerID;

SELECT * FROM order_type_view;

SELECT C_Name, BerryTypeFROM order_type_viewWHERE BerryType IN (SELECT BerryTypeFROM order_type_viewWHERE C_Name= 'Steve Ballmer');

--#4 Create a sequence for adding customers.

DROP SEQUENCE CUSTOMER_SEQ;

CREATE SEQUENCE CUSTOMER_SEQINCREMENT BY 1START WITH 0007MAXVALUE 0100MINVALUE 0NOCYCLENOCACHE;

INSERT INTO CustomerVALUES (CUSTOMER_SEQ.NEXTVAL, 'Russell Wilson', 4111, 'N Brooks ST', 'Bellevue', 'WA', 98045, '[email protected]');SELECT * FROM CUSTOMER;

--#5 How many (distinct) customers have ordered Blackberries?SELECT DISTINCT COUNT(o.customerID) "num_customer"

16

Page 17: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

FROM orderItem oi, customer c, orders oWhere c.customerID = o.customerIDAND o.orderID = oi.orderIDAND berrytype = 'Blackberry';

--#6 Which customers have a total charge more than $35?Select c_name, SUM(charge) "total charge"From order_charge_viewGroup By c_name HAVING SUM(charge) > 35;

--#7 How many pounds of each berry have been sold already?SELECT BerryType, CONCAT(SUM(Quantity), ' lb') “Total Quantity”FROM ORDERITEMGROUP BY BerryType;

--#8 How many orders has Paul Allen made?select count(customerID)from orderswhere customerID=4;

--#9 Which customers are in our system, but have yet to made an order?SELECT CustomerID, C_NameFROM CustomerMINUSSELECT c.CustomerID, C_NameFROM Orders o, Customer cWHERE o.CustomerID = c.CustomerID;

POST-IMPLEMENTATION

MANAGERIAL AND ORGANIZATIONAL IMPACTS Spooner Berry Farms have seen our database and are considering using it to replace their

hand written system of records. This database contains valuable information about customers, locations, and berries being sold. Spooner Berry Farms can use our data to track deliveries,

17

Page 18: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

berries being sold at specific locations and who is buying these berries. This information is important because it saves valuable data into a stored location that will remember it. MAINTENANCE

Managers will be trained to monitor and update the database so that they can optimize effective use of the data collected. They are also now able to have a formal database in order to enter new customers, employees, and other information that will help them better track their business and allow for more growth in the future.

GROWTH AND CHANGEOur goals for this project were to create a database for Spooner Berry Farms. This change

will be very big since they were only using paper documentation before. As seen with some of the functional queries we have created, they now, in addition to storing data, can analyze their data more usefully. This can help them see what is most popular for Spooner Berry Farms or other practical information. Before only having data, they know have a useful way to use it to better customer relationships and have a more user friendly way to monitor.

CONCLUSIONFrom working with this project and our experience as a whole, we really discovered how

useful Oracle implementation can truly be. We were able to take a business that had no database and assess their needs in order to create our Entity-Relationship Diagram. Then with normalization, we were able to create a database to ensure no anomalies were present so maintenance would be correct and so our implementation was efficient. Creating the structure of the database, we were able to enter relevant data that we believed would benefit Spooner Berry Farms. By going through these steps, we were able to create a database using Oracle to allow Spooner Berry Farms continue to grow and be able to efficiently store data in a useful manner. We suggest that they utilize a database because we have observed how helpful it is in comparison to their current paper documentation.

SPOOLED FILE:

SQL>SQL> -- Oracle SQL, Term Project Phase IIISQL> -- BMIS441-01SQL> -- GROUP 1

18

Page 19: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

SQL> -- Spooner Berry FarmSQL>SQL> SET LINESIZE 150SQL> SET PAGESIZE 45SQL>SQL> DROP TABLE Delivery CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE Employee CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE EmployeeType CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE Location CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE OrderItem CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE Product CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE Orders CASCADE CONSTRAINTS;

Table dropped.

SQL> DROP TABLE Customer CASCADE CONSTRAINTS;

Table dropped.

SQL>SQL>SQL> --Creating tables and inserting dataSQL>SQL> CREATE TABLE CUSTOMER 2 (CustomerID NUMBER(4), 3 C_Name VARCHAR(23), 4 C_Address NUMBER(5), 5 C_Street VARCHAR(20),

19

Page 20: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

6 C_City VARCHAR(20), 7 C_State CHAR(2), 8 C_Zip NUMBER(5), 9 C_Email VARCHAR(40), 10 CONSTRAINT customer_customerid_pk PRIMARY KEY (CustomerID));

Table created.

SQL>SQL> INSERT INTO Customer 2 VALUES(0001, 'Bill Gates', 1835, '73rd Ave', 'Medina', 'WA', 98039, '[email protected]');

1 row created.

SQL>SQL> INSERT INTO Customer 2 VALUES(0002, 'Jeff Bezos', 2093, 'Evergreen Point Rd', 'Medina', 'WA', 98039, '[email protected]');

1 row created.

SQL>SQL> INSERT INTO Customer 2 VALUES(0003, 'Howard Schultz', 1500, 'E 42nd Ave', 'Seattle', 'WA', 98112, '[email protected]');

1 row created.

SQL>SQL> INSERT INTO Customer 2 VALUES(0004, 'Paul Allen', 6555, 'W Mercer Way', 'Mercer Island', 'WA', 98040, '[email protected]');

1 row created.

SQL>SQL> INSERT INTO Customer 2 VALUES(0005, 'Steve Ballmer', 3832, 'Hunts Point Rd', 'Hunts Point', 'WA', 98004, '[email protected]');

1 row created.

SQL>SQL> INSERT INTO Customer

20

Page 21: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

2 VALUES(0006, 'Pierce Fleming', 1122, 'River Road', 'Spokane', 'WA', 98202, '[email protected]');

1 row created.

SQL>SQL> CREATE TABLE ORDERS 2 (OrderID NUMBER(4), 3 CustomerID NUMBER(4), 4 PaymentType VARCHAR2(10), 5 Satisfaction NUMBER(1), 6 CONSTRAINT ORDERS_OrderID_pk PRIMARY KEY (OrderID), 7 CONSTRAINT ORDERS_CustomerID_fk FOREIGN KEY (CustomerID) 8 References CUSTOMER (customerID));

Table created.

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1001, 0004, 'Credit', 3 );

1 row created.

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1002, 0005, 'Cash', 4);

1 row created.

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1003, 0001, 'Credit', 2);

1 row created.

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1004, 0005, 'Debit', 3);

1 row created.

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1005, 0003, 'Cash', 2 );

1 row created.

21

Page 22: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1006, 0002, 'Debit', 4);

1 row created.

SQL>SQL> INSERT INTO ORDERS 2 VALUES(1007, 0004, 'Debit', 5);

1 row created.

SQL>SQL>SQL> CREATE TABLE PRODUCT 2 (BerryType VARCHAR(15), 3 Cost NUMBER(4), 4 Retail NUMBER(4), 5 CONSTRAINT product_berrytype_pk PRIMARY KEY (BerryType));

Table created.

SQL>SQL> INSERT INTO Product 2 VALUES('Raspberry', 2.00, 4.00);

1 row created.

SQL>SQL> INSERT INTO Product 2 VALUES('Blueberry', 1.50, 3.00);

1 row created.

SQL>SQL> INSERT INTO Product 2 VALUES('Strawberry', 2.50, 5.00);

1 row created.

SQL>SQL> INSERT INTO Product 2 VALUES('Blackberry', 2.00, 5.00);

1 row created.

22

Page 23: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

SQL>SQL> INSERT INTO Product 2 VALUES('Marionberry', 1.00, 2.00);

1 row created.

SQL>SQL> CREATE TABLE ORDERITEM 2 (OrderID NUMBER(4), 3 BerryType VARCHAR(15), 4 Quantity NUMBER(3), 5 CONSTRAINT ORDERITEM_OrderID_pk PRIMARY KEY (OrderID,BerryType), 6 CONSTRAINT ORDERITEM_OrderID_fk FOREIGN KEY (OrderID) 7 References ORDERS (OrderID), 8 CONSTRAINT ORDERITEM_BerryType_fk FOREIGN KEY (BerryType) 9 References PRODUCT (BerryType));

Table created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1001,'Raspberry', 5);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1002,'Blackberry', 7);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1002,'Strawberry', 7);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1003,'Blueberry', 6);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM

23

Page 24: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

2 VALUES(1004,'Strawberry', 4);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1005,'Strawberry', 3);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1005,'Blackberry', 4);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1006,'Marionberry',6);

1 row created.

SQL>SQL> INSERT INTO ORDERITEM 2 VALUES(1007,'Strawberry', 4);

1 row created.

SQL>SQL>SQL> CREATE TABLE LOCATION 2 (locationID NUMBER(3), 3 L_Name VARCHAR(20), 4 L_Street VARCHAR2(50), 5 L_City VARCHAR2(10), 6 L_State CHAR(2), 7 L_Zip NUMBER(5), 8 CONSTRAINT location_locationid_pk PRIMARY KEY (locationID));

Table created.

SQL>SQL>SQL> INSERT INTO Location 2 VALUES(001, 'Tumwater','5200 Capital Blvd', 'Tumwater', 'WA', 98501);

24

Page 25: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(002, 'Olympia', 'Ralph''s Thriftway 1908 4th Ave E', 'Olympia', 'WA', 98506);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(003, 'Aberdeen', '1213 East Wishkah Street', 'Aberdeen', 'WA', 9820);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(004, 'Shelton', '1826 Olympic Hwy N. ', 'Shelton', 'WA', 98584);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(005, 'Centralia', '1215 Harrison', 'Centralia', 'WA', 98531);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(006, 'Westside of Olympia','2010 Harrison Ave NW', 'Olympia', 'WA', 98502);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(007, 'North Seattle', '7726 35th Ave NE', 'Seattle', 'WA', 98115);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(008, 'Yelm', '1109 E. Yelm Ave', 'Yelm', 'WA', 98597);

1 row created.

SQL>SQL> INSERT INTO Location

25

Page 26: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

2 VALUES(009, 'Farm', '3327 Yelm Hwy', 'Olympia', 'WA', 98513);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(010, 'Farmers Market','700 Capitol Way', 'Olympia', 'WA', 98501);

1 row created.

SQL>SQL> INSERT INTO Location 2 VALUES(011, 'Hawks Prairie','1200 Marvin Rd NE', 'Lacey', 'WA', 98516);

1 row created.

SQL>SQL> CREATE TABLE EMPLOYEETYPE 2 (TypeID NUMBER(3), 3 Description VARCHAR2(20), 4 CONSTRAINT employeetype_typeid_pk PRIMARY KEY (typeID));

Table created.

SQL>SQL> INSERT INTO Employeetype 2 VALUES(001, 'Manager');

1 row created.

SQL>SQL> INSERT INTO Employeetype 2 VALUES(002, 'Berry Picker');

1 row created.

SQL>SQL> INSERT INTO Employeetype 2 VALUES(003, 'Casher');

1 row created.

SQL>SQL> INSERT INTO Employeetype 2 VALUES(004, 'Driver');

26

Page 27: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

1 row created.

SQL>SQL>SQL> CREATE TABLE Employee 2 (EmployeeID NUMBER(3), 3 E_Name VARCHAR(23), 4 LocationID NUMBER(3), 5 TypeID NUMBER(3), 6 Date_Employed DATE, 7 HourlyPay NUMBER(3), 8 CONSTRAINT Employee_EmployeeID_pk PRIMARY KEY (EmployeeID), 9 CONSTRAINT Employee_LocationID_fk FOREIGN KEY (LocationID) 10 References Location (LocationID), 11 CONSTRAINT Employee_TypeID_fk FOREIGN KEY (TypeID) 12 References EmployeeType (TypeID));

Table created.

SQL>SQL> INSERT INTO Employee 2 VALUES(101, 'Sue Spooner',009,001,'10-JUN-1985', 17);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(102, 'Tim Spooner',009,001,'10-AUG-1985', 17);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(103, 'Megan Birge',010,003, '20-JUN-2008', 14.5);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(104, 'Nick Birge', 005,003, '07-JUN-2013', 13.5);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(105, 'Cobi Beal', 006, 003, '02-JUN-2016', 11.5);

27

Page 28: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(106, 'Taylor Bellamy', 001, 003, '05-JUN-2016', 11.5);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(107, 'George Smith', 001, 004, '07-JUN- 2014', 13.0);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(108, 'Tyler Parks', 009, 002, '10-JUN-2007', 14.5);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(109, 'Stan Lee', 009, 002, '04-JUN-1998', 15);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(110, 'Gary Tillman', 003, 003, '07-JUN-2005', 15.0);

1 row created.

SQL>SQL> INSERT INTO Employee 2 Values(111, 'Jill White', 004, 003, '28-MAY-2010', 14.0);

1 row created.

SQL> INSERT INTO Employee 2 Values (112, 'Joe Jackson', 007, 004, '03-JUN-2015', 13.0);

1 row created.

SQL>SQL> INSERT INTO Employee

28

Page 29: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

2 Values (113, 'Macey Cobb', 008, 004, '13-JUN-2016', 12.5);

1 row created.

SQL>SQL> CREATE TABLE Delivery 2 (DeliveryID NUMBER(3), 3 EmployeeID NUMBER(3), 4 LocationID NUMBER(3), 5 Quantity NUMBER(3), 6 DeliveryCost NUMBER(4), 7 CONSTRAINT Delivery_DeliveryID_pk PRIMARY KEY (DeliveryID), 8 CONSTRAINT Delivery_EmployeeID_fk FOREIGN KEY (EmployeeID) 9 References Employee (EmployeeID), 10 CONSTRAINT Delivery_LocationID_fk FOREIGN KEY (LocationID) 11 References Location (LocationID));

Table created.

SQL>SQL> INSERT INTO Delivery 2 Values (201, 107, 001, 150, 10);

1 row created.

SQL>SQL> INSERT INTO Delivery 2 Values (202, 112, 007, 200, 30);

1 row created.

FUNCTION QUERIES

SQL>SQL> INSERT INTO Delivery 2 Values (203, 113, 008, 85, 15);

1 row created.

SQL>SQL>SQL> --Creating ViewsSQL>SQL> CREATE OR REPLACE VIEW customer_satisfaction_view(CustomerID, C_Name, OrderID, satisfaction) 2 AS SELECT c.customerid, c.c_name, o.orderid, o.satisfaction

29

Page 30: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

3 FROM customer c, orders o 4 WHERE c.customerid = o.customerid 5 ORDER BY c.c_name;

View created.

SQL>SQL> SELECT * FROM customer_satisfaction_view;

CUSTOMERID C_NAME ORDERID SATISFACTION

---------- ----------------------- ---------- ------------

1 Bill Gates 1003 2

3 Howard Schultz 1005 2

2 Jeff Bezos 1006 4

4 Paul Allen 1001 3

4 Paul Allen 1007 5

5 Steve Ballmer 1002 4

5 Steve Ballmer 1004 3

7 rows selected.

SQL>SQL> CREATE OR REPLACE VIEW order_charge_view(customerid, c_name, orderid, charge) 2 AS SELECT c.customerid, c.c_name, o.orderid, (oi.quantity * p.retail) 3 FROM customer c, orders o, orderitem oi, product p 4 WHERE c.customerid = o.customerid 5 AND o.orderid = oi.orderid 6 AND oi.berrytype = p.berrytype 7 ORDER BY c.c_name;

View created.

SQL>SQL> SELECT * FROM order_charge_view;

30

Page 31: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

CUSTOMERID C_NAME ORDERID CHARGE

---------- ----------------------- ---------- ----------

1 Bill Gates 1003 18

3 Howard Schultz 1005 20

3 Howard Schultz 1005 15

2 Jeff Bezos 1006 12

4 Paul Allen 1007 20

4 Paul Allen 1001 20

5 Steve Ballmer 1002 35

5 Steve Ballmer 1002 35

5 Steve Ballmer 1004 20

9 rows selected.

SQL>SQL> CREATE OR REPLACE VIEW order_cost_view(customerid, c_name, orderid, cost) 2 AS SELECT c.customerid, c.c_name, o.orderid, (oi.quantity * p.cost) 3 FROM customer c, orders o, orderitem oi, product p 4 WHERE c.customerid = o.customerid 5 AND o.orderid = oi.orderid 6 AND oi.berrytype = p.berrytype 7 ORDER BY c.c_name;

View created.

SQL>SQL> SELECT * FROM order_cost_view;

CUSTOMERID C_NAME ORDERID COST

---------- ----------------------- ---------- ----------

1 Bill Gates 1003 12

31

Page 32: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

3 Howard Schultz 1005 8

3 Howard Schultz 1005 9

2 Jeff Bezos 1006 6

4 Paul Allen 1007 12

4 Paul Allen 1001 10

5 Steve Ballmer 1002 14

5 Steve Ballmer 1002 21

5 Steve Ballmer 1004 12

9 rows selected.

SQL> --FUNCTIONAL QUERIES:SQL>SQL> --#1 Which customers have a satisfaction rating lower or equal to 3?SQL> SELECT cv.C_Name, cv.Satisfaction, c.C_Email 2 FROM customer_satisfaction_view cv, CUSTOMER c 3 WHERE cv.C_Name = c.C_Name 4 AND Satisfaction <= 3;

C_NAME SATISFACTION C_EMAIL

----------------------- ------------ ----------------------------------------

Bill Gates 2 [email protected]

Howard Schultz 2 [email protected]

Paul Allen 3 [email protected]

Steve Ballmer 3 [email protected]

SQL>SQL> --#2 How much did each order in total charge the customers?SQL> Select orderid, customerID, c_name, SUM(charge) "total charge" 2 From order_charge_view 3 Group By orderid, customerID, c_name;

32

Page 33: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

ORDERID CUSTOMERID C_NAME total charge

---------- ---------- ----------------------- ------------

1004 5 Steve Ballmer 20

1006 2 Jeff Bezos 12

1003 1 Bill Gates 18

1002 5 Steve Ballmer 70

1001 4 Paul Allen 20

1005 3 Howard Schultz 35

1007 4 Paul Allen 20

7 rows selected.

SQL>SQL> --#3 Who has purchased the same berry type as Steve Ballmer?SQL> CREATE OR REPLACE VIEW order_type_view (c_name, BerryType) 2 AS SELECT c.C_Name, oi.BerryType 3 FROM CUSTOMER c, ORDERS o, ORDERITEM oi 4 WHERE oi.OrderID=o.OrderID 5 AND o.CustomerID=c.CustomerID;

View created.

SQL>SQL> SELECT * FROM order_type_view;

C_NAME BERRYTYPE

----------------------- ---------------

Paul Allen Raspberry

Steve Ballmer Blackberry

Steve Ballmer Strawberry

Bill Gates Blueberry

33

Page 34: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

Steve Ballmer Strawberry

Howard Schultz Blackberry

Howard Schultz Strawberry

Jeff Bezos Marionberry

Paul Allen Strawberry

9 rows selected.

SQL>SQL> SELECT C_Name, BerryType 2 FROM order_type_view 3 WHERE BerryType IN (SELECT BerryType 4 FROM order_type_view 5 WHERE C_Name= 'Steve Ballmer');

C_NAME BERRYTYPE

----------------------- ---------------

Steve Ballmer Blackberry

Steve Ballmer Strawberry

Steve Ballmer Strawberry

Howard Schultz Blackberry

Howard Schultz Strawberry

Paul Allen Strawberry

6 rows selected.

SQL>SQL> --#4 Create a sequence for adding customers.SQL>SQL> DROP SEQUENCE CUSTOMER_SEQ;

Sequence dropped.

34

Page 35: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

SQL>SQL> CREATE SEQUENCE CUSTOMER_SEQ 2 INCREMENT BY 1 3 START WITH 0007 4 MAXVALUE 0100 5 MINVALUE 0 6 NOCYCLE 7 NOCACHE;

Sequence created.

SQL>SQL> INSERT INTO Customer 2 VALUES (CUSTOMER_SEQ.NEXTVAL, 'Russell Wilson', 4111, 'N Brooks ST', 'Bellevue', 'WA', 98045, '[email protected]');

1 row created.

SQL> SELECT * FROM CUSTOMER;

CUSTOMERID C_NAME C_ADDRESS C_STREET C_CITY C_ C_ZIP C_EMAIL ---------- ----------------------- ---------- -------------------- -------------------- -- ---------- ---------------------------------------- 1 Bill Gates 1835 73rd Ave Medina WA 98039 [email protected] 2 Jeff Bezos 2093 Evergreen Point Rd Medina WA 98039 [email protected] 3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 [email protected] 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 [email protected] 5 Steve Ballmer 3832 Hunts Point Rd Hunts Point WA 98004 [email protected] 6 Pierce Fleming 1122 River Road Spokane WA 98202 [email protected] 7 Russell Wilson 4111 N Brooks ST Bellevue WA 98045 [email protected]

7 rows selected.

SQL>SQL> --#5 How many (distinct) customers have ordered Blackberries?SQL> SELECT DISTINCT COUNT(o.customerID) "num_customer" 2 FROM orderItem oi, customer c, orders o 3 Where c.customerID = o.customerID

35

Page 36: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

4 AND o.orderID = oi.orderID 5 AND berrytype = 'Blackberry';

num_customer

------------

2

SQL>SQL> --#6 Which customers have a total charge more than $35?SQL> Select c_name, SUM(charge) "total charge" 2 From order_charge_view 3 Group By c_name 4 HAVING SUM(charge) > 35;

C_NAME total charge

----------------------- ------------

Paul Allen 40

Steve Ballmer 90

SQL>SQL> --#7 How many pounds of each berry have been sold already?SQL> SELECT BerryType, CONCAT(SUM(Quantity), ' lb') "Total Quantity" 2 FROM ORDERITEM 3 GROUP BY BerryType;

BERRYTYPE Total Quantity

--------------- -------------------------------------------

Blueberry 6 lb

Marionberry 6 lb

Blackberry 11 lb

Raspberry 5 lb

Strawberry 18 lb

36

Page 37: €¦ · Web view3 Howard Schultz 1500 E 42nd Ave Seattle WA 98112 hschultz@starbucks.com 4 Paul Allen 6555 W Mercer Way Mercer Island WA 98040 paul@vulcan.com 6 Pierce Fleming 1122

SQL>SQL> --#8 How many orders has Paul Allen made?SQL> select count(customerID) 2 from orders 3 where customerID=4;

COUNT(CUSTOMERID)

-----------------

2

SQL>SQL> --#9 Which customers are in our system, but have yet to made an order?SQL> SELECT CustomerID, C_Name 2 FROM Customer 3 MINUS 4 SELECT c.CustomerID, C_Name 5 FROM Orders o, Customer c 6 WHERE o.CustomerID = c.CustomerID;

CUSTOMERID C_NAME

---------- -----------------------

6 Pierce Fleming

7 Russell Wilson

SQL>SQL>SQL>SQL>SQL>SQL>SQL>SQL>SQL>SQL> Spool off

37


Recommended