Post on 07-Feb-2017
PlayBall Inc. Management Report – Group 5
Christina Peltrop, Oscar Valencia, Spencer Cerruto, Sean Santerre, Matthew Waldron
Professor Morelli
Database Management Systems
12/7/16
Part 1
Company Description & Strategic Planning Factors
Playball! Inc. is retail company that specializes in sports equipment, clothing, books as well as
videos for baseball, basketball, football, soccer, and Gulf. Playball! Currently has over 48,000
customers with a projected growth rate of about 10% per year during the next two years. By
2008, PlayBall! had an inventory of over 1,000 products with the number of products growing
18% since 2007. The inventory is expected to grow 14% over the next two years. Customer
satisfaction is extremely important for Playball! and its customers. With that being said, rapid
shipment of orders and efficient management are a particularly high-priority concern. Although
efficient inventory management has kept back-orders to a minimum, Playball! wants to further
reduce back-orders and advance order fulfillment rates. In addition, due to Playball!’s liberal
return policy of defective products and products that do not meet customer satisfaction, Playball!
would like to minimize the number of returns by reducing defects and by providing a detailed
description of their products to its customers.
As Is Business Process Flow
Key Problems
● Product information can be hard to locate if customer does not know product code
● No way to track vendor quality
● No way to analyze customer information
● No inventory report, sales, or commission reports
● Cannot track sales performance of individual customer representatives
● Repetitive steps in ordering process
Proposed Business Solution
Product class, type, category information normalized from PRODUCT TABLE
o Run inventory reports on different combination of products
o Each product has a unique identifier (SKU) to quickly find products
o Other fields such as name, type, class, category can be used to find the product
ORDER_ITEM TABLE tracks individual line item information normalized from the CUST_ORDER TABLE
o Allows aggregate line items to be associated with one order
CUST_ORDER TABLE is associated with the CUSTOMER TABLE
o Can be joined to track customer’s orders and total amount spent
o Can also be joined with ORDER_ITEM TABLE to track individual line item purchases
o Ability to determine PlayBall’s best customers
INVOICE TABLE tracks invoices from the CUST_ORDER TABLE associated with each employee in the EMPLOYEE TABLE
o Can be joined to obtain how much each employee sold, number of total invoices, and their commission amount.
o Ability to determine PlayBall’s best employees.
PRODUCT TABLE designed to keep track of inventory
o Keeps track of current quantity and reorder quantity amount if inventory is too low.
o Associated with ORDER_ITEM TABLE to determine the frequency of products purchased, order quantity, and backorder quantity.
o ORDER_ITEM TABLE will update the PRODUCT TABLE to reflect current inventory levels
VENDOR TABLE can be linked with PRODUCT and ORDER_ITEM TABLES to determine quality of vendors.
o ORDER_ITEM TABLE tracks product defects and return quantity.
o Can be joined with PRODUCT and VENDOR TABLES to determine Playball’s best vendors.
To Be Business Process Flow
Data Requirements & Data Definitions
Ability to find product information quickly through quick searches of product class, type, category, and specific product item.
Track employees’ associated orders to measure sales performance. Analyze and measure vendor quality by tracking backorder quantity and customer returns
resulting from defects. Assess customer loyalty by tracking the number of purchases and total costs spent by
each customer. Ability to generate inventory, sales, and commission reports. Quantity amounts for each
product type, class, and category, order item sales, total sale amount, and employee commission amounts are needed.
Part 2 & Part 3
Conceptual Model Diagram
Relational Model Diagram
Microsoft SQL Server 2014 Generated Diagram
Create Tables and Relationships
Create table CUSTOMER (
CustID int not null,
FName varchar (20) not null,
LName varchar (20) not null,
Street varchar (25) not null,
Country varchar (25) not null,
Zip char (5) not null,
Phone char (12) not null,
Email varchar (30) not null,
MemberSince char (10) not null,
Birthdate char (10) not null,
Constraint PK_CustID PRIMARY KEY (CustID)
);
Create table EMPLOYEE (
EmpID int not null,
FName varchar (25) not null,
LName varchar (25) not null,
Street varchar (25) not null,
Country varchar (25) not null,
Zip char (5) not null,
CellPhone char (12) not null,
WorkPhone char (12) not null,
Email varchar (25) not null,
Salary decimal (10,2) not null,
HireDate char (10) not null,
BirthDate char (10) not null,
Constraint PK_EmpID PRIMARY KEY (EmpID)
);
Create table VENDOR (
VendorID int not null,
VendorName varchar (25) not null,
ContactFN varchar (25) not null,
ContactLN varchar (25) not null,
Street varchar (25) not null,
City varchar (25) not null,
State varchar (25) not null,
Country varchar (25) not null,
Zip char (5) not null,
Phone char (12) not null,
Email varchar (25) not null,
Fax char (12) not null,
HomePage varchar (25) not null,
Constraint PK_VendorID PRIMARY KEY (VendorID));
Create table SHIPPER (
ShipperID int not null,
CompanyName varchar (20) not null,
Phone char (12) not null,
Email varchar (25) not null,
Constraint PK_ShipperID PRIMARY KEY (ShipperID)
);
Create table PROD_CLASS (
ProdClassID int not null,
ClassName varchar (25) not null,
ClassDesc varchar (50) not null,
Constraint PK_ProdClassID PRIMARY KEY (ProdClassID) );
Create table PROD_CATEGORY (
ProdCatID int not null,
CategoryName varchar (25) not null,
CategoryDesc varchar (50) not null,
Constraint PK_ProdCatID PRIMARY KEY (ProdCatID)
);
Create table CUST_BILL_ADDRESS (
BillingID int not null,
CustID int not null,
Bill_Name varchar (50) not null,
Bill_Address varchar (25) not null,
Bill_State varchar (25) not null,
Bill_Zip char (5) not null,
Constraint PK_BillingID PRIMARY KEY (BillingID),
Constraint FK_CustID FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID)
);
Create table PAYMENT (
CardNum char (16) not null,
CustID int not null,
Company varchar (15) not null,
Type varchar (15) not null,
Security_Code char (3) not null,
Expiration_Date char (5) not null,
Constraint PK_CardNum PRIMARY KEY (CardNum),
Constraint FK_CustID1 FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID)
);
Create table PROD_TYPE(
ProdTypeID int not null,
TypeName varchar(25) not null,
TypeDesc varchar(50) not null,
Constraint PK_ProdTypeID PRIMARY KEY (ProdTypeID)
);
Create table PRODUCT (
SKU int not null,
VendorID int not null,
ProductName varchar (35) not null,
ProdClassID int not null,
ProdTypeID int not null,
ProdCatID int not null,
ProdDesc varchar (100) not null,
VendorUnitPrice decimal (10,2) not null,
CurrentQuantity decimal (10,2) not null,
ReorderQuantity decimal (10,2) not null,
Constraint PK_SKU PRIMARY KEY (SKU),
Constraint FK_VendorID FOREIGN KEY (VendorID) REFERENCES VENDOR (VendorID),
Constraint FK_ProdClassID FOREIGN KEY (ProdClassID) REFERENCES PROD_CLASS (ProdClassID),
Constraint FK_ProdTypeID FOREIGN KEY (ProdTypeID) REFERENCES PROD_TYPE (ProdTypeID),
Constraint FK_ProdCatID FOREIGN KEY (ProdCatID) REFERENCES PROD_CATEGORY (ProdCatID)
);
Create table CUST_ORDER (
OrderID int not null,
CustID int not null,
Shipping_Name varchar (50) not null,
Shipping_Address varchar (25) not null,
Shipping_State varchar (20) not null,
Shipping_ZIP char (5) not null,
ShipperID int not null,
OrderDate char (10) not null,
ShipDate char (10) not null,
BillingID int not null,
CardNum char (16) not null,
SubTotal decimal (10,2) not null,
Discount decimal (10,2) not null,
ShippingPrice decimal (10,2) not null,
SalesTax decimal (10,2) not null,
TotalCost decimal (10,2) not null,
Constraint PK_OrderID PRIMARY KEY (OrderID),
Constraint FK_CustID2 FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID),
Constraint FK_ShipperID FOREIGN KEY (ShipperID) REFERENCES SHIPPER (ShipperID),
Constraint FK_BillingID FOREIGN KEY (BillingID) REFERENCES CUST_BILL_ADDRESS (BillingID),
Constraint FK_CardNum FOREIGN KEY (CardNum) REFERENCES PAYMENT (CardNum)
);
Create table ORDER_ITEM (
OrderItemID int not null,
OrderID int not null,
SKU int not null,
Quantity decimal(10,2) not null,
UnitPrice decimal (10,2) not null,
ExtendedPrice decimal (10,2) not null,
BackorderQuantity decimal (10,2) not null,
ReturnQuantity decimal (10,2) not null,
Defective decimal (10,2) not null,
Constraint PK_OrderItemID PRIMARY KEY (OrderItemID),
Constraint FK_OrderID FOREIGN KEY (OrderID) REFERENCES Cust_ORDER (OrderID),
Constraint FK_SKU FOREIGN KEY (SKU) REFERENCES PRODUCT (SKU)
);
CREATE TABLE INVOICE (
InvoiceNum INT NOT NULL,
EmpID INT NOT NULL,
OrderID INT NOT NULL,
CommissionAmount decimal (10,2) NOT NULL,
CONSTRAINT PK_INVOICE PRIMARY KEY(Invoice_Num),
CONSTRAINT FK_EmpID FOREIGN KEY (EmpID) REFERENCES EMPLOYEE (EmpID),
CONSTRAINT FK_OrderID2 FOREIGN KEY(OrderID) REFERENCES CUST_ORDER (OrderID)
);
Data Population
insert into CUSTOMER VALUES (1000,'Jon','Snow','35 Ballad Lane', 'USA', 06010,
'860-555-5551', 'J.Snow@gmail.com', 2007,'01/06/1986');
insert into CUSTOMER VALUES (1001, 'Ramsay', 'Bolton', '13 Happy Drive', 'USA', 06091,
'203-555-1313', 'R.Bolton@gmail.com', 2009, '10/13/1988');
insert into CUSTOMER VALUES (1002, 'Daenerys', 'Targaryn', '47 Dragon Street', 'USA', 06852,
'860-555-5286', D.Targaryn@gmail.com', 2006, '09/16/1987');
insert into CUSTOMER VALUES(1003, 'Tyrion', 'Lannister', '1616 Dwarf Trail', 'USA', 06883,
'860-555-4686', 'T.Lannister@gmail.com',2010, '03/06/1984');
insert into CUSTOMER VALUES(1004, 'Margery', 'Tyrell', '608 Flower Circuit', 'USA', 06001,
'860-555-1069', 'M.Tyrell@gmail.com', 2001, '08/22/1991');
insert into CUSTOMER VALUES(1005, 'Cersei', 'Lannister','609 Shale Drive', 'USA', 08602,
'860-555-9368', 'C.Lannister@gmail.com', 2006, '10/03/1973');
insert into EMPLOYEE VALUES(100, 'Jeff', 'Hoffer', '4257 Oakridge Farm lane', 'USA', 06050,
'860-707-5550', '860-979-0025', 'J.Hoffer14@gmail.com', 45000.00,'02/27/2006', '09/16/1989');
insert into EMPLOYEE VALUES(101, 'Mary', 'Prescott', '4511 Dale Avenue', 'USA', 06050,
'860-707-7385', '860-979-0025', 'M.Prescott@gmail.com', 48000.00, '03/09/2006', '05/28/1983');
insert into EMPLOYEE VALUES(102, 'Stanley', 'Murphy', '3052 Goodwin avenue', 'USA', 06062,
'860-707-9063', '860-979-0025', 'S.Murphy@gmail.com', 50000.00, '09/16/2006', '11/17/1980');
insert into EMPLOYEE VALUES(103, 'Jeff', 'Swarma', '1003 Clinton Drive', 'USA', 06010,
'860-707-3597', '860-979-0029', 'J.Swarma@gmail.com', 60000.00, '02/13/1980', '12/17/1980');
insert into EMPLOYEE VALUES(104, 'Janice', 'Duncan', '986 Colony Street', 'USA', 06090,
'860-707-3355', '860-979-1003', 'J.Duncan@gmail.com', 61000.00, '06/25/2006', '07/14/1979');
insert into EMPLOYEE VALUES(105, 'Vanessa', 'Smith', '9610 Ward Street', 'USA', 06034,
'860-707-6570', '860-979-1004', 'V.Smith@gmail.com', 65000.00, '03/02/2006', '01/17/1983');
insert into CUST_BILL_ADDRESS VALUES(10, 1000, 'Jon Snow','35 Ballad Lane', 'CT', 06010);
insert into CUST_BILL_ADDRESS VALUES(11, 1001, 'Ramsay Bolton', '13 Happy Drive', 'CT', 06091);
insert into CUST_BILL_ADDRESS VALUES(12, 1002, 'Daenerys Targaryn', '47 Dragon Street', 'CT', 06852);
insert into CUST_BILL_ADDRESS VALUES(13, 1003, 'Tyrion Lannister', '1616 Dwarf Trail', 'CT', 06883);
insert into CUST_BILL_ADDRESS VALUES(14, 1004, 'Margery Tyrell', '608 Flower Circuit', 'CT', 06001);
insert into CUST_BILL_ADDRESS VALUES(15, 1005, 'Cersei Lannister','609 Shale Drive', 'CT', 08602);
insert into PAYMENT VALUES (5056086718166963, 1000, 'Visa', 'Credit Card', '204', '03/18' );
insert into PAYMENT VALUES (0567001364665822, 1001, 'MasterCard', 'Debit', '047', '12/21' );
insert into PAYMENT VALUES (7530830495075146, 1002, 'Visa', 'Debit', '101', '06/19' );
insert into PAYMENT VALUES (8612472258726202, 1003, 'Visa', 'Credit Card', '036', '03/19' );
insert into PAYMENT VALUES (9580079447020825, 1004, 'Chase', 'Credit Card', '992', '10/17' );
insert into PAYMENT VALUES (0016098502629749, 1005, 'MasterCard', 'Credit Card', '726', '06/18');
Insert into VENDOR values( 9600, 'SportWorks', 'Bob', 'Jones', '111 Main Street', 'New Britain', 'CT', 'USA', 06999, '800-596-1122', 'sportworks@gmail.com', '800-596-2233', 'sportworks.com');
Insert into VENDOR VALUES( 9610, 'Olympian', 'Dave', 'Ingra','23 Clinton Avenue', 'Bristol', 'CT','USA', 06010, '800-555-1060', 'olympian@gmail.com', '800-555-1876','olympian.com');
Insert into SHIPPER values( 18600, 'UPS', '800-534-2163','ups@gmail.com');
Insert into SHIPPER VALUES( 18610, 'FEDEX', '800-515-1839', 'fedex@gmail.com');
Insert into PROD_CLASS Values(364, 'Baseball Card', 'A card');
Insert into PROD_CLASS Values(360, 'Baseball Jersey', 'A jersey');
Insert into PROD_CLASS Values(362, 'Baseball Video', 'A video');
Insert into PROD_CLASS Values(361, 'Golf Club', 'A golf club');
Insert into PROD_CATEGORY Values(1708, 'Baseball', 'Baseball Items');
Insert into PROD_CATEGORY Values(1700, 'Baseball', 'Baseball Attire');
Insert into PROD_CATEGORY Values(1701, 'Golf', 'Golf Clubs');
Insert into PROD_CATEGORY Values(1702, 'Baseball', 'Baseball Videos');
Insert into PROD_TYPE Values(8924, 'Baseball Card', 'A card');
Insert into PROD_TYPE Values(8922, 'Baseball Jersey', 'A jersey');
Insert into PROD_TYPE Values(8927, 'Baseball Video', 'A video');
Insert into PROD_TYPE Values(8921, 'Golf Club', 'A golf club');
/* Run individually */
insert into PRODUCT VALUES(1092, 9600, 'Derek Jeter Card', 364, 8924, 1708, 'Best shortstop to ever live', '45.00',2, 1);
Insert into PRODUCT VALUES (1093, 9600, 'NY Yankees Jersey', 360, 8922, 1700, 'Cool jersey', '45.00',2,32);
Insert into PRODUCT VALUES (1095, 9610, '2008 World Series Video', 362, 8927, 1702, 'Watch the Phillies get lucky', '30.00', 48, 2);
Insert into PRODUCT VALUES(1094, 9610, 'Titanium Driver, Cobra', 361, 8921, 1701, 'Only Driver You’ll Ever Need', '325.00',8,10);
/* Run individually */
insert into CUST_ORDER VALUES (9000, 1000, 'Jon Snow', '35 Ballad Lane', 'CT', 06010, 18600, '11/03/2016', '11/03/2016', 10, 5056086718166963, '135.00', '0.00', '3.00', '13.00', '151.00');
Insert into CUST_ORDER VALUES (9001, 1001, 'Ramsay Bolton', '13 Happy Drive', 'CT', 06091, 18600, '11/04/2016', '11/06/2016', 11, 0567001364665822, '60.00', '0.00', '3.00', '6.00', '69.00');
insert into CUST_ORDER VALUES (9002, 1002, 'Daenerys Targaryn', '47 Dragon Street', 'CT', 06852, 18610, '11/17/2016', '11/18/2016', 12, 7530830495075146, '550.00', '50.00', '5.00', '35.00', '540.00');
Insert into CUST_ORDER VALUES( 9003, 1003, 'Tyrion Lannister', '1616 Dwarf Trail', 'CT', 06883, 18610, '11/21/2016', '11/25/2016', 13, 8612472258726202, '45.00', '0', '3.00', '6.00', '54.00');
/* Run individually */
insert into ORDER_ITEM VALUES (900, 9000, 1092, '2', '45.00', '90.00', '0', '1', '1');
insert into ORDER_ITEM VALUES (901, 9000, 1093, '1', '45.00', '45.00', '1', '0', '0');
Insert into ORDER_ITEM VALUES (902, 9001, 1095, '2', '30.00','60.00', '0','2','0');
insert into ORDER_ITEM VALUES (903, 9002, 1094, '1', '325.00', '325.00', '1', '0', '0');
insert into ORDER_ITEM VALUES (904, 9002, 1093, '3', '45.00', '135.00', '0', '2', '2');
insert into ORDER_ITEM VALUES (905, 9002, 1092, '2', '45.00', '90.00', '0', '0', '0');
insert into ORDER_ITEM VALUES (906, 9003, 1093, '1', '45.00', '45.00', '1', '0', '0');
/* Run individually */
Insert into INVOICE VALUES (10101, 100, 9000, '15.00');
Insert into INVOICE VALUES (10102, 101, 9001, '6.90');
Insert into INVOICE VALUES (10103, 102, 9002, '54.00');
Insert into INVOICE VALUES (10104, 102, 9003, '5.40');
SQL Reports (1-3) – (Using Microsoft SQL Server 2014)
Inventory Summary Report
CREATE VIEW Inventory_Summary_Report AS
SELECT P_CLASS.ClassName, P_TYPE.TypeName, P_CAT.CategoryName, P.CurrentQuantity
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
INNER JOIN PROD_CLASS AS P_CLASS
ON P.ProdClassID = P_CLASS.ProdClassID
INNER JOIN PROD_TYPE AS P_TYPE
ON P.ProdTypeID = P_TYPE.ProdTypeID
INNER JOIN PROD_CATEGORY AS P_CAT
ON P.ProdCatID = P_CAT.ProdCatID
GROUP BY P_CLASS.ClassName, P_TYPE.TypeName, P_CAT.CategoryName, P.CurrentQuantity;
Inventory Detail Report
CREATE VIEW Inventory_Detail_Report AS
SELECT P.ProductName, P_CLASS.ClassName, P.CurrentQuantity, OI.Quantity, OI.BackorderQuantity
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
INNER JOIN PROD_CLASS AS P_CLASS
ON P.ProdClassID = P_CLASS.ProdClassID
GROUP BY P.ProductName, P.CurrentQuantity, P_CLASS.ClassName, OI.Quantity, OI.BackorderQuantity;
Sales and Commissions Report
CREATE VIEW Sales_Commission_Report AS
SELECT E.EmpID, E.FName, E.LName, I.InvoiceNum, CO.OrderDate, CO.TotalCost, I.CommissionAmount
FROM CUST_ORDER AS CO JOIN INVOICE AS I
ON CO.OrderID = I.OrderID
JOIN EMPLOYEE AS E
ON E.EmpID = I.EmpID
GROUP BY E.EmpID, E.FName, E.LName, I.InvoiceNum, CO.OrderDate, CO.TotalCost, I.CommissionAmount;
Information Requirement Queries – (Using Microsoft SQL Server 2014)
1. How many invoices were written by each employee in a given month?
SELECT E.EmpID, E.FName, E.LName,
COUNT (DISTINCT CO.OrderID) AS TotalInvoiceWritten
FROM CUST_ORDER AS CO JOIN INVOICE AS I
ON CO.OrderID = I.OrderID
JOIN EMPLOYEE AS E
ON E.EmpID = I.EmpID
WHERE CO.OrderDate BETWEEN '11/01/2016' AND '11/31/2016'
GROUP BY E.EmpID, E.FName, E.LName
ORDER BY COUNT (DISTINCT CO.OrderID);
2. Which employee sold the most in a given month?
SELECT E.EmpID, E.FName, E.LName,
SUM (CO.TotalCost) AS TotalAmountSold
FROM CUST_ORDER AS CO JOIN INVOICE AS I
ON CO.OrderID = I.OrderID
JOIN EMPLOYEE AS E
ON E.EmpID = I.EmpID
WHERE CO.OrderDate BETWEEN '11/01/2016' AND '11/31/2016'
GROUP BY E.EmpID, E.FName, E.LName
ORDER BY SUM (CO.TotalCost);
3. Which products are ordered the most/least often?
SELECT P.ProductName,
COUNT (OI.Quantity) AS OrderAmount
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
GROUP BY P.ProductName
ORDER BY COUNT (OI.Quantity) DESC;
4. Which products were backordered for more than a specified number of orders (or the most in a given month)?
SELECT P.ProductName,
SUM (OI.BackorderQuantity) AS BackorderQuantity
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
JOIN CUST_ORDER AS CO
ON CO.OrderID = OI.OrderID
WHERE CO.OrderDate BETWEEN '11/01/2016' AND '11/31/2016'
GROUP BY P.ProductName
ORDER BY SUM (OI.BackorderQuantity);
5. Which products were defective for more than a specified number of orders (or the most in a given month)?
SELECT P.ProductName,
SUM (OI.Defective) AS DefectiveQuantity
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
JOIN CUST_ORDER AS CO
ON CO.OrderID = OI.OrderID
WHERE CO.OrderDate BETWEEN '11/01/2016' AND '11/31/2016'
GROUP BY P.ProductName
ORDER BY SUM (OI.Defective);
6. For each product class and type combination, we need to know how many products were ordered.
SELECT P_CLASS.ClassName,
COUNT (OI.Quantity) AS OrderAmount
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
JOIN PROD_CLASS AS P_CLASS
ON P.ProdClassID = P_CLASS.ProdClassID
GROUP BY P_CLASS.ClassName
ORDER BY COUNT (OI.Quantity);
SELECT P_TYPE.TypeName,
COUNT (OI.Quantity) AS OrderAmount
FROM PRODUCT AS P INNER JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
JOIN PROD_TYPE AS P_TYPE
ON P.ProdTypeID = P_TYPE.ProdTypeID
GROUP BY P_TYPE.TypeName
ORDER BY COUNT (OI.Quantity);
7. To whom should we give ‘most favored vendor’ status?
SELECT V.VendorName,
SUM (OI.BackorderQuantity) AS BackorderAmount,
SUM (OI.Defective) AS DefectiveAmount
FROM VENDOR AS V INNER JOIN PRODUCT AS P
ON V.VendorID = P.VendorID
JOIN ORDER_ITEM AS OI
ON P.SKU = OI.SKU
GROUP BY V.VendorName
ORDER BY SUM (OI.BackorderQuantity), SUM (OI.Defective);
8. Which are our best customers?
SELECT C.FName, C.LName, C.MemberSince,
SUM (CO.TotalCost) AS TotalAmountPurchased,
COUNT (CO.OrderID) AS TotalInvoice
FROM CUSTOMER AS C INNER JOIN CUST_ORDER AS CO
ON C.CustID = CO.CustID
GROUP BY C.FName, C.LName, C.MemberSince
ORDER BY SUM (CO.TotalCost) DESC, COUNT (CO.OrderID);