1. Lakeshore Auto Database System Project
Sunny Okoro
DBST651, Spring 2011
Graduate School
University of Maryland University College
2. Table of Contents
Deliverable 1 – Statement of Work (SOW).........................................................................................................................................................................2
Overview: ............................................................................................................................................................................................................................2
Purpose and Objective: ........................................................................................................................................................................................................2
Diagram Tool .......................................................................................................................................................................................................................2
Database...............................................................................................................................................................................................................................2
Composition Software .........................................................................................................................................................................................................3
Hardware and Software .......................................................................................................................................................................................................3
DDL, TCL and DML ...........................................................................................................................................................................................................3
Deliverable 2 – ERD............................................................................................................................................................................................................3
Deliverable 3 – DDL (Data Definition Language) ..............................................................................................................................................................6
Deliverable 4 – DML (Data Manipulation Language) ............................................................................................................................................................19
Insert Statements ..................................................................................................................................................................................................................19
Reports. .....................................................................................................................................................................................................................................52
1
3. Deliverable 1 – Statement of Work (SOW)
Overview:
I will create a database for Lakeshore car dealership as part of their web system. This database would keep track for number of cars sold and number of
cars that are repaired at their shop.
Purpose and Objective:
This database will enable clients to buy their car or service their car without filling the paper works. New clients can have their information entered
into the system enabling a speedy service next time they return for a new car or repair service. The web service would allow clients to make appointment
for car repair service or for a new car sale which are sent directly to the shop or sales associates housed in Oracle DB. The DB can also be used by
managers to produce monthly and weekly statistical reports.
Diagram Tool
Oracle SQL Developer Data Molder
Database
Oracle 11g
2
4. Composition Software
Notepad +++ for writing and editing SQL commands
Hardware and Software
Microsoft Windows 7 Professional x64
DDL, TCL and DML
Oracle SQL would be used for the Data Definition, Data Manipulation and Transaction Control languages of to build the database. I would also use
Database objects including constraints, views, index and sequences to generate unique values for Primary Key.
Deliverable 2 – ERD
3
6. ERD Description
Customer Table
A customer can be associated with one or more repair record(s).
A customer should place one or more reservation(s).
A customer can be associated with one or more car sale(s).
Car Sales Table
A Car sale must be associated with one agent
One or more car sales must be associated with a car
Agent Table
An agent must be associated with one or more car sales
Mechanic Table
A mechanic must be associated with one or more repair record(s)
Reservations Table
One or more reservations must be associated to a customer.
Car Table
A car must be associated with one or more car sale(s)
5
7. Repair Record
A car must be associated with one or more repair record(s)
One or more repair records must be associated with a mechanic.
Deliverable 3 – DDL (Data Definition Language)
I grouped all the DDL for a particular table in one area to make it easier to read. I did not use the drop statement because there were no needs for me to
use them since I have not created any of these objects before even though I included them on this document.
***** Customer Table *****
/* creates the car sales table but first I had to check if a table has the same name with a drop statement */
Drop table "customer";
Create table "customer"
(Customer_id Number constraint customer_cust_id_pk primary key,
First_Name VARCHAR2(35),
Middle_Name VARCHAR2(35),
Last_Name VARCHAR2(35),
Address VARCHAR2(30),
Address_2 VARCHAR2(25),
6
8. City VARCHAR2(30),
Cust_State VARCHAR2(3),
Zip_Code NUMBER,
Phone_1 NUMBER,
Phone_2 NUMBER,
Email VARCHAR2(30)
);
/* Creates a sequence to hold PK for customer table. I used the drop statement to check if any sequence has been created before with the same name */
Drop Sequence customer_cust_id_seq;
CREATE SEQUENCE customer_cust_id_seq
Start with 090090
Increment by 40
nocycle;
/*Adds the not null constraints to allows each columns with this constraint to have value*/
Alter table "customer"
modify (First_Name constraint cust_first_name_nn not null)
modify (Middle_Name constraint cust_middle_name_nn not null)
modify (Last_Name constraint cust_last_name_nn not null)
modify(Address constraint cust_address_nn not null)
modify(city constraint cust_city_nn not null)
modify(cust_state constraint cust_state_nn not null)
modify(phone_1 constraint cust_phone_1_nn not null);
***** Agent Table Begins *****
7
9. /* Creates table agent to hold all information relating to an agent beginning with drop statement to check if a table has been created before with same
name.*/
Drop table "agent";
Create table "agent"
( Agent_ID Number constraint agennt_agent_id_pk primary key,
First_Name VARCHAR2(35),
Middle_Name VARCHAR2(35),
Last_Name VARCHAR2(35),
Address VARCHAR2(50),
City VARCHAR2(30),
Agent_State VARCHAR2(3),
Zip_Code NUMBER,
Phone Number,
Phone_2 Number,
Email VARCHAR2(30)
);
/* Creates sequence to generate unique id for agent table request id. Used the drop statement to check if a sequence with same name has been created
before.*/
Drop sequence agent_agent_id_seq;
CREATE SEQUENCE agent_agent_id_seq
start with 008000
increment by 079
nocycle;
/* Adds the not null constraint to make sure each column has a value specified by upon input.*/
8
10. Alter table "agent"
modify (First_Name constraint aget_first_name_nn not null)
modify (Middle_Name constraint aget_middle_name_nn not null)
modify (Last_Name constraint aget_last_name_nn not null)
modify(Address constraint aget_address_nn not null)
modify(city constraint aget_city_nn not null)
modify(agent_state constraint aget_state_nn not null)
modify(phone constraint aget_phone_1_nn not null);
***** Car Table Begins*****
/* Creates the table repair record but first I have to check if any table has been created before using the same name with the drop statement.*/
/*creates the car table to hold data related to cars*/
Drop table "car";
Create table "car"
(
Car_Id NUMBER constraint car_car_id_pk primary key,
Brand_Name VARCHAR2(30),
Model Number,
Year_Made NUMBER,
Notes blob
);
/* Creates the not null constraints to make sure each column contains data*/
9
11. Alter table "car"
modify (Brand_Name constraint car_Brand_Name_nn not null)
modify (Model constraint car_Model_nn not null)
modify (Year_Made constraint car_Year_Made_nn not null);
/* Adds the column marker to the car table.*/
Alter table "car"
add maker varchar2(34);
/* Creates the not null constraints to make sure each column contains data*/
Alter table "car"
modify (maker constraint car_maker_nn not null);
/* Creates the sequence to produce the car_id PK value but first I have to check if any sequence has been created before using the same name with the
drop statement.*/
Drop sequence car_car_id_seq;
CREATE SEQUENCE car_car_id_seq
start with 2000
increment by 02
nocycle;
***** Car Sales Table Begins *****
/*Creates the car sales table but first I had to check if a table has the same name with a drop statement.*/
Drop table CarSales;
10
12. Create table CarSales
(
Transaction_ID Number constraint carsales_transaction_id_pk primary key,
Agent_Id Number,
Car_Id Number,
Sales_Date NUMBER,
Amount_Paid_Cash NUMBER,
Amount_Paid_check NUMBER,
Amount_Paid_Loan NUMBER,
Total_Paid NUMBER,
Remaning_Amoount NUMBER,
Payment_Plan NUMBER,
Number_Months NUMBER,
Number_Days NUMBER
);
/*Creates a sequence to hold PK for car sales table. I used the drop statement to check if any sequence has been created before with the same name. */
Drop Sequence carsales_trans_id_seq;
CREATE SEQUENCE carsales_trans_id_seq
start with 0899999
increment by 089
nocycle;
/*Change the sales_date column data type to date*/
Alter table CarSales
modify sales_date date default sysdate;
/* Adds the null constraint meaning that each column specified won’t contain null data */
11
13. Alter table CarSales
modify (agent_id constraint csale_agent_id_nn not null)
modify (car_id constraint csale_car_id_nn not null)
modify (sales_date constraint csale_sales_date_nn not null)
modify(total_paid constraint csale_total_paid_nn not null);
/* Adds the customer_id column to hold the FK value to link customer table and car sales table */
Alter table CarSales
Add customer_id number;
/*Adds the foreign keys needed to link car sales table with agent, car and customer tables */
Alter table CarSales
Add constraint csale_car_id_fk foreign key (car_id)
References "car"(Car_id) on delete cascade;
Alter table CarSales
Add constraint csale_agent_id_fk foreign key(agent_id)
references "agent"(agent_id)on delete cascade;
Alter table CarSales
Add constraint csale_customer_id_fk foreign key(customer_id)
references "customer"(customer_id) on delete cascade;
Alter table CarSales
MODIFY(Customer_id constraint csale_customer_id_nn not null);
Alter table CarSales
rename column remaning_amoount to remaning_amount;
12
14. ***** Reservation Table Begins *****
/* Creates table reservations beginning with drop statement to check if a table has been created before with same name. */
Drop table "reservations";
Create table "reservations"
(
Request_Id Number constraint reservation_request_id_pk primary key,
Request_Date Number,
Request_Time Number,
Request_Type VARCHAR2(15),
Service_Option VARCHAR2(15),
Customer_Id NUMBER,
Notes BLOB
);
/*Adds the not null constraint to make sure each column has a value specified by an input */
Alter table "reservations"
modify (Request_Date constraint resv_request_Date_nn not null)
modify (Request_Time constraint resv_request_Time_nn not null)
modify (Request_Type constraint resv_request_Type_nn not null);
Alter table "reservations"
Modify (Customer_Id constraint resrvation_customer_id_nn not null);
13
15. /*Adds the foreign key constraint to link customer and reservation tables*/
Alter table "reservations"
add constraint reserv_customer_id_fk foreign key (customer_id) references "customer" (customer_id) on delete cascade;
/* Creates sequence to generate unique id for reservation table request id. Used the drop statement to check if a sequence with same name has been
created before.*/
Drop sequence reservation_request_id_seq;
CREATE SEQUENCE reservation_request_id_seq
start with 0789999
increment by 089
nocycle;
/*These check constraints make sure that user selected a particular service when making reservations*/
Alter table "reservations"
Add constraint resvs_request_type_ck check ( Request_Type in ('car sale', 'car loan', 'car browsing','service'));
Alter table "reservations"
Add constraint resv_service_option_ck check(service_option in ('oil change', 'battery change', 'tire change', 'repair', 'other'));
/* Change the request_date column data type to date*/
Alter table "reservations"
Modify request_date date default sysdate;
14
16. /*Drop the column notes since it has Binary large Object data type meant for media files*/
Alter table "reservations"
Drop column notes;
/* Adds the notes column with the right data type character large object to hold text*/
Alter table "reservations"
Add Notes clob;
***** Mechanic Table Begins*****
/*Creates table to hold mechanic contact information beginning with drop statement to check if a table has been created before with same name. */
Drop table "mechanic";
Create table "mechanic"
(Mechanic_ID Number ,
First_Name VARCHAR2(35),
Middle_Name VARCHAR2(35),
Last_Name VARCHAR2(35),
Address VARCHAR2(50),
City VARCHAR2(30),
Agent_State VARCHAR2(3),
Zip_Code NUMBER,
15
17. Phone Number,
Phone_2 Number,
Email VARCHAR2(30)
);
/*Add the primary key constraint to the mechanic table*/
ALTER TABLE "mechanic"
add constraint mechanic_mechanic_id_pk primary key(Mechanic_ID);
/*change the name of the column which happened due to a copy and paste error*/
ALTER TABLE "mechanic"
Rename column Agent_State to mechanic_State;
/*Creates sequence to generate unique id for mechanic table request id. Used the drop statement to check if a sequence with same name has been created
before.*/
Drop sequence meach_meachinic_id_seq;
CREATE SEQUENCE meach_meachinic_id_seq
start with 007000
increment by 030
nocycle;
/*Adds the not null constraint to make sure each column has a value specified by an input.*/
Alter table "mechanic"
modify (First_Name constraint meach_first_name_nn not null)
modify (Middle_Name constraint meach_middle_name_nn not null)
16
18. modify (Last_Name constraint meach_last_name_nn not null)
modify(Address constraint meach_address_nn not null)
modify(city constraint meach_city_nn not null)
modify(mechanic_State constraint meach_state_nn not null)
modify(phone constraint meach_phone_1_nn not null
***** Repair Record Table Begins*****
/* Creates the table repair record but first I have to check if any table has been created before using the same name with the drop statement.*/
Drop table RepairRecord;
Create table RepairRecord
(Repair_Id NUMBER Constraint repair_repair_id_pk primary key,
Repair_Date DATE DEFAULT SYSDATE,
Mechanic_ID Number,
Car_Id Number,
Customer_id Number,
Mileage Number,
Oil_Change VARCHAR2(3),
Battery_Change VARCHAR2(3),
Tire_Change VARCHAR2(3),
Repair_Services VARCHAR2(3),
Repair_Notes BLOB,
Body_Paint VARCHAR2(15),
Mechanic_Notes CLOB,
Amount_Charged NUMBER,
Credit_Card_Number NUMBER,
EXP_DATE DATE DEFAULT SYSDATE,
CASH NUMBER );
17
19. /* creates the not null constraints to make sure each column contains data*/
Alter table RepairRecord
Modify (amount_charged constraint repair_amount_charged_nn not null)
Modify (mechanic_id constraint repair_mechanic_id_nn not null);
/* These constraints make sure that particular repair service or services are performed. */
Alter table RepairRecord
Add constraint repair_oil_change check (Oil_Change in ('yes', 'no'));
Alter table RepairRecord
Add constraint repair_Battery_change check (Battery_change in ('yes', 'no'));
Alter table RepairRecord
Add constraint repair_tire_change check (tire_change in ('yes', 'no'));
Alter table RepairRecord
Add constraint repair_repair_service check (repair_services in ('yes', 'no'));
/* Adds the foreign key constraint linking the repair record tables with the mechanic, car, and customer tables. */
Alter table RepairRecord
Add constraint repair_mechanic_id_fk foreign key(Mechanic_ID)
References "mechanic"(Mechanic_ID) ON DELETE CASCADE;
Alter table RepairRecord
Add constraint repair_customer_id_fk foreign key(customer_ID)
References "customer"(customer_ID) ON DELETE CASCADE;
18
20. Alter table RepairRecord
Add constraint repair_car_id_fk foreign key(car_ID)
References "car"(car_id) ON DELETE CASCADE;
/* Drop the column repair notes */
Alter table RepairRecord
DROP COLUMN Repair_Notes;
/* Adds the repair_notes with character large objects to hold mechanic notes which may be text format with multiple sentences*/
Alter table RepairRecord
Add repair_notes clob;
/* Creates the sequence to create the repair_id values for the repair record table. I have to check to see if any sequence has been created using the same
name with the drop statement. */
Drop sequence repair_id_seq;
CREATE SEQUENCE repair_id_seq
start with 2000
increment by 0208
nocycle;
Deliverable 4 – DML (Data Manipulation Language)
Insert Statements
/*The following commands inserts data into table customer */
19
28. values (agent_agent_id_seq.nextval, 'maryanne', 'linda', 'stephine', '89 churchhill' ,'lake', 'in', 46408, 00000, 'na');
/* inserts data into reservations*/
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, TO_DATE('31-Jan-2011','DD-MON-YYYY'),1500,'service','oil change',
(select customer_id from "customer" where customer_id = 90490 ) );
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id, notes)
values (reservation_request_id_seq.nextval, TO_DATE('31-jan-2011','DD-MON-YYYY'),1500,'service','battery change',
(select customer_id from "customer" where customer_id = 90530 ),
'My car has not be starting well. It ptoduce a Squish sound each time.' );
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'), 0935, 'service','tire change',
(select customer_id from "customer" where customer_id = 90570));
27
29. Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'), 0930, 'service','tire change',
(select customer_id from "customer" where customer_id = 90610));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id, notes)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'), 1045, 'service','oil change',
(select customer_id from "customer" where customer_id = 90650), 'i had been having problem with the two front tires');
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'),1125,'service','battery change',
(select customer_id from "customer" where customer_id = 90690));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'),1125,'service','repair',
(select customer_id from "customer" where customer_id = 90650));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'),1125,'service','repair',
28
30. (select customer_id from "customer" where customer_id = 90730));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'),1125,'service','repair',
(select customer_id from "customer" where customer_id = 90770));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'), 0945, 'car sale',
(select customer_id from "customer" where customer_id = 90810 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'), 0900, 'car sale',
(select customer_id from "customer" where customer_id = 91010 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('31-jan-2011', 'DD-MON-YYYY'), 1045, 'car sale',
(select customer_id from "customer" where customer_id = 91130 ));
29
31. Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011','
DD-MON-YYYY'), 1025, 'car loan',(select customer_id from "customer" where customer_id = 91210 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011','
DD-MON-YYYY'), 1345,'car loan',(select customer_id from "customer" where customer_id = 91250 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011', 'DD-MON-YYYY'),1200,
'service','repair',(select customer_id from "customer" where customer_id = 90090));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011', 'DD-MON-YYYY'), 1345, 'service',
'oil change',(select customer_id from "customer" where customer_id = 90090 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
30
32. values (reservation_request_id_seq.nextval, To_Date('01-feb-2011', 'DD-MON-YYYY'), 1405, 'service',
'oil change',(select customer_id from "customer" where customer_id = 90170 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011', 'DD-MON-YYYY'), 1120, 'car sale',
(select customer_id from "customer" where customer_id = 90170 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011', 'DD-MON-YYYY'), 1045,
'car sale',
(select customer_id from "customer" where customer_id = 90410 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('01-feb-2011', 'DD-MON-YYYY'), 1505, 'service',
'repair',(select customer_id from "customer" where customer_id = 91090 ));
31
33. Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 1520, 'car browsing',
(select customer_id from "customer" where customer_id = 90810 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 1100, 'car browsing',
(select customer_id from "customer" where customer_id = 90890 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 0935, 'service','repair',
(select customer_id from "customer" where customer_id = 90570));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id, notes)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 0930, 'service','repair',
(select customer_id from "customer" where customer_id = 90770), 'I had a car accident with a truck on my way to work');
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
32
34. values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 1045, 'service','repair',
(select customer_id from "customer" where customer_id = 90650));
Insert into "reservations"(request_id, request_date, request_time,request_type,service_option,customer_id)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'),1125,'service','battery change',
(select customer_id from "customer" where customer_id = 91130));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 0945, 'car sale',
(select customer_id from "customer" where customer_id = 91170 ));
Insert into "reservations"(request_id, request_date, request_time,request_type,customer_id)
values (reservation_request_id_seq.nextval, To_Date('02-feb_2011', 'DD-MON-YYYY'), 0900, 'car sale',
(select customer_id from "customer" where customer_id = 90970 ));
/* insert data into car */
Insert into "car" (car_id, brand_name, model, year_made, maker)
33
38. values (car_car_id_seq.nextval, 'Genesis', '2010', '2009', 'hyndai');
Insert into "car" (car_id, brand_name, model, year_made, maker)
values (car_car_id_seq.nextval, 'Genesis', '2011', '2010', 'hyndai');
/* insert data into mechanic table */
insert into "mechanic"(mechanic_id, first_name, middle_name, last_name, phone, address, city, mechanic_state, zip_code)
values(meach_meachinic_id_seq.nextval, 'Johnnattan', 'Winewood', 'Bryon', 6308977465, '5261 County Blvd','West Chicago', 'IL',
60426);
insert into "mechanic"(mechanic_id, first_name, middle_name, last_name, phone, address, city, mechanic_state, zip_code)
values(meach_meachinic_id_seq.nextval, 'Johnson', 'Mark', 'Luther', 8158979465, '4235 Justice Blvd Apt 2b','homewood', 'IL',
60345);
insert into "mechanic"(mechanic_id, first_name, middle_name, last_name, phone, address, city, mechanic_state, zip_code)
values(meach_meachinic_id_seq.nextval, 'Greg', 'Cliffton', 'Luther', 8152306824, '4235 Justice Blvd Apt 2b','homewood', 'IL',
60345);
37
39. insert into "mechanic"(mechanic_id, first_name, middle_name, last_name, phone, address, city, mechanic_state, zip_code)
values(meach_meachinic_id_seq.nextval, 'Drew', 'thomas', 'Luther', 8152306824, '4235 Justice Blvd Apt 2b','homewood', 'IL',
60345);
insert into "mechanic"(mechanic_id, first_name, middle_name, last_name, phone, address, city, mechanic_state, zip_code)
values(meach_meachinic_id_seq.nextval, 'Hendron', 'washington', 'D.Mario', 7734123456, '6503 Chicago Rd ','doltin', 'IL', 60145);
insert into "mechanic"(mechanic_id, first_name, middle_name, last_name, phone, address, city, mechanic_state, zip_code)
values(meach_meachinic_id_seq.nextval, 'justice', 'brown', 'mario', 8476899876, '606 highway 23 apt3c ','doltin', 'IL', 60145);
/* insert data into repair record */
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7000), (select car_id from "car" where car_id =2048), 90610 ,
55000,'no', 'no','yes',
69.99, 69.99);
38
40. Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7000), (select car_id from "car" where car_id =2046),90570,
55000,'no', 'no','yes',
69.99, 69.99);
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7000), (select car_id from "car" where car_id =2036), 90650,
45000,'yes', 'no','no',
70.99, 70.99);
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
39
41. Amount_charged, cash)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7120), (select car_id from "car" where car_id =2040), 90690 ,
45000,'no', 'no','no', 'yes',
90.99, 90.99);
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7120), (select car_id from "car" where car_id =2066),90530 ,
45000,'no', 'no','no', 'yes',
90.99, 90.99);
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes, mechanic_notes)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
40
42. ( Select mechanic_id from "mechanic" where mechanic_id = 7000), (select car_id from "car" where car_id =2058),90730
,35000,'yes', 'no','no', 'no',
290.99, 90.99, 'fixed the transmission system and the right window frame', 'right door main frame had to be repaced');
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes, mechanic_notes)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7120), (select car_id from "car" where car_id =2044),90770
,35000,'yes', 'no','no', 'no',
190.99, 90.99, 'fixed the oil tank', 'discoverd a hole during inspection.showed it to customer agreed for change');
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes, mechanic_notes)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7000), (select car_id from "car" where car_id =2070),90650
,55000,'yes', 'no','no', 'no',
41
43. 290.99, 90.99, 'fixed the front bumper', 'repair both front and back bumpers due to car accident');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('31-jan-2011', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7000), (select car_id from "car" where car_id =2036), 90490,
45000,'yes', 'no','no',
70.99, 70.99);
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('01-FEB-11 ', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7030), (select car_id from "car" where car_id =2066), 90410 ,
45000,'yes', 'no','no',
70.99, 70.99);
42
44. Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('01-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7030), (select car_id from "car" where car_id =2042),91050 ,
45000,'yes', 'no','no',
70.99, 70.99);
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes, mechanic_notes)
values (repair_id_seq.nextval, to_date('01-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7030), (select car_id from "car" where car_id =2068),90090
,5000,'no', 'yes','no', 'no',
40.99, 40.99, 'fixed the cup holder', 'the holder won’t close');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes, mechanic_notes)
43
45. values (repair_id_seq.nextval, to_date('01-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7030), (select car_id from "car" where car_id =2070),91250
,15000,'no', 'yes','no', 'no',
110.99, 110.99, 'fixed the driver passanger chair', 'the chair wont move forward');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('02-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7090), (select car_id from "car" where car_id =2074),90570
,5000,'no', 'yes','no', 'no',
100.99, 100.99, 'installed new tv set');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('02-FEB-11', 'dd-mon-yyyy'),
44
46. ( Select mechanic_id from "mechanic" where mechanic_id = 7120), (select car_id from "car" where car_id =2038), 90770
,55000,'no', 'yes','no', 'no',
490.99, 490.99, 'body paint');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('02-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2066), 90650
,5000,'no', 'yes','no', 'no',
209, 209.99, 'air system replaced');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash)
values (repair_id_seq.nextval, to_date('02-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2066), 91130
,5000,'no', 'no','no', 'yes',
45
47. 50, 50);
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('03-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2048), 90330
,5000,'no', 'yes','no', 'no',
60, 60, 'replace the front lights');
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('03-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2074), 91010
,2000,'no', 'yes','no', 'no',
60, 60, 'replace the break lights');
46
48. Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('03-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2074),
91210,2000,'no', 'no','no', 'yes',
50, 50, 'na');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('03-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2036 ), 90770
,89000,'no', 'yes','no', 'no',
50, 50, 'fixed the horn system');
Insert into RepairRecord(repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
47
49. values (repair_id_seq.nextval, to_date('04-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2056 ), 90450
,1000,'no', 'yes','no', 'no',
150, 150, 'fixed the break system');
Insert into RepairRecord (repair_id, repair_date, mechanic_id, car_id, customer_id, mileage,
oil_change,repair_services,tire_change,battery_change,
Amount_charged, cash, repair_notes)
values (repair_id_seq.nextval, to_date('04-FEB-11', 'dd-mon-yyyy'),
( Select mechanic_id from "mechanic" where mechanic_id = 7150), (select car_id from "car" where car_id = 2056 ), 90970
,2000,'no', 'no','yes', 'no',
80, 80, 'na');
/* insert data into the car sales. */
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT , customer_id)
values (carsales_trans_id_seq.nextval, 8079,
48
50. (select car_id from "car" where car_id = 2012),
to_date ('31-jan-2011', 'dd-mon-yyyy'),
19000, 0,19000,0, 90810);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8158), (select car_id from "car" where
car_id = 2022), to_date ('31-jan-2011', 'dd-mon-yyyy'), 0, 20890,0 ,20890, 12, 24, 91010);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8079), (select car_id from "car" where
car_id = 2030), to_date ('31-jan-2011', 'dd-mon-yyyy'),
14000, 6500, 14000 ,6500, 12, 12, 91130);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8316), (select car_id from "car" where
car_id = 2006), to_date ('01-FEB-11', 'dd-mon-yyyy'),
49
51. 14000, 0, 14000 ,0, 0, 0, 91170 );
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8316), (select car_id from "car" where
car_id = 2034), to_date ('01-FEB-11', 'dd-mon-yyyy'),
12000, 0, 12000 ,0, 0, 0, 91250);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8237), (select car_id from "car" where
car_id = 2040), to_date ('02-FEB-11', 'dd-mon-yyyy'),
10000, 0, 10000 ,0, 0, 0, 91250);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8316), (select car_id from "car" where
car_id = 2032), to_date ('02-FEB-11', 'dd-mon-yyyy'),
0, 21000, 0 ,21000, 12, 38, 91170);
50
52. insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8000), (select car_id from "car" where
car_id = 2010), to_date ('03-FEB-11', 'dd-mon-yyyy'),
0, 21890, 0 ,21890, 12, 38, 90970);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8158), (select car_id from "car" where
car_id = 2002), to_date ('03-FEB-11', 'dd-mon-yyyy'),
0, 21890, 0 ,21890, 12, 38, 90890);
insert into CarSales ( transaction_id, agent_id, car_id, sales_date, amount_paid_check, amount_paid_loan, total_paid,
REMANING_AMOUNT, payment_plan, number_months , customer_id)
values (carsales_trans_id_seq.nextval, (select agent_id from "agent" where agent_id = 8158), (select car_id from "car" where
car_id = 2028 ), to_date ('04-FEB-11', 'dd-mon-yyyy'),
0, 21890, 0 ,21890, 12, 38, 91010);
51
53. Reports.
/* manager wants to know which clients came in for car loan or car browsing*/
select customer_id, to_char(request_date , 'dd-mon-yyyy') as Request_Date, request_time, initcap(request_type) as Request_Type
from "reservations" where request_type ='car loan' or request_type ='car browsing';
CUSTOMER_ID REQUEST_DATE REQUEST_TIME REQUEST_TYPE
91210 1-Feb-11 1025 Car Loan
91250 1-Feb-11 1345 Car Loan
90810 2-Feb-11 1520 Car Browsing
90890 2-Feb-11 1100 Car Browsing
52
54. /*Manager wants to know which clients came in for car sale*/
select customer_id, to_char(request_date) as Request__Date, request_time, initcap(request_type) as Request_Type from
"reservations" where request_type ='car sale' ;
CUSTOMER_ID REQUEST__DATE REQUEST_TIM REQUEST_TYPE
90810 31-Jan-11 945 Car Sale
91010 31-Jan-11 900 Car Sale
91130 31-Jan-11 1045 Car Sale
90170 1-Feb-11 1120 Car Sale
90410 1-Feb-11 1045 Car Sale
91170 2-Feb-11 945 Car Sale
90970 2-Feb-11 900 Car Sale
53
55. /*manager wants to know which client received which service for service option */
54
57. /*Manger wants to know which clients don’t have any phone number listed */
select initcap (first_name)||','||initcap(last_name) as Client_Name, customer_id, phone_1 from "customer" where phone_1 = 0;
CLIENT_NAME CUSTOMER_ID PHONE_1
Abel,Adan 90490 0
Alethia,Deborah 90530 0
Abel,Adan 90570 0
Nnneka,Okolo 90650 0
Shu,Chin 90690 0
Ernest,Jackson 90730 0
Miksovsky,Joe 90770 0
Joshua,Randall 90810 0
Kathryn,Wilson 90890 0
Keith,Harris 90930 0
Linda,Kobara 91010 0
/* updates the phone to have a value */
update "customer"
set phone_1 = 31234590904
where customer_id = 90890;
56
58. update "customer"
set Phone_1 = 2192248902
where customer_id = 90930;
update "customer"
set Phone_1 = 8159091450
where customer_id = 91130;
update "customer"
set Phone_1 = 6304408903
where customer_id = 91170;
update "customer"
set Phone_1 = 8154408903
where customer_id = 91210;
update "customer"
set Phone_1 = 7737338470
where customer_id = 91250;
update "customer"
set Phone_1 = 7097338470
where customer_id = 91290;
update "customer"
set Phone_1 = 31293484567
where customer_id = 91330;
57
59. update "customer"
set Phone_1 = 31989081234
where customer_id = 91410;
update "customer"
set Phone_1 = 2198800903
select customer_id, city, address, cust_state, phone_1 from "customer" where phone_1 = 0;
no rows selected
/* manager wants to update clients with missing contacts */
select customer_id, city, address, cust_state from "customer" where address = 'na';
CUSTOMER_ID CITY ADDRESS CUST_STATE
90530 na na na
90810 na na na
90890 na na na
/* update the customer table to fill in the missing values*/
58
60. update "customer"
set city ='indiana city'
where customer_id = 90530;
update "customer"
set address = '9090 michigan ave'
where customer_id = 90530;
update "customer"
set cust_state = 'IN'
where customer_id = 90530;
UPDATE "customer"
set zip_code=41909
where customer_id = 90530;
update "customer"
set city ='indiana city'
where customer_id = 90810;
update "customer"
set address = '401 ceder lake blv apt 23'
where customer_id = 90810;
update "customer"
set cust_state = 'IN'
where customer_id = 90810;
UPDATE "customer"
59
61. set zip_code=41909
where customer_id = 90810;
update "customer"
set city ='indiana city'
where customer_id =90890;
update "customer"
set address = '401 ceder lake nw blvd'
where customer_id = 90890;
update "customer"
set cust_state = 'IN'
where customer_id = 90890;
UPDATE "customer"
set zip_code=41909
where customer_id = 90890;
select customer_id, city, address, cust_state from "customer" where address = 'na';
no rows selected
/* Manager wants to determine which customer had their cars repaired */
select c.customer_id, r.mechanic_id ,r.repair_date, r.repair_notes from "customer" c inner join "repair record" r
on c.customer_id = r.customer_id ;
60
62. CUSTOMER_ID MECHANIC_ID REPAIR_DATE REPAIR_NOTES
90650 7000 31-Jan-11
90690 7120 31-Jan-11
90530 7120 31-Jan-11
90730 7000 31-Jan-11 Fixed The Transmission System And The Right Window Frame
90770 7120 31-Jan-11 Fixed The Oil Tank
90650 7000 31-Jan-11 Fixed The Front Bumper
90490 7000 31-Jan-11
90410 7030 1-Feb-11
91050 7030 1-Feb-11
90090 7030 1-Feb-11 Fixed The Cup Holder
91250 7030 1-Feb-11 Fixed The Driver Passanger Chair
90570 7090 2-Feb-11 Installed New Tv Set
90770 7120 2-Feb-11 Body Paint
90650 7150 2-Feb-11 Air System Replaced
91130 7150 2-Feb-11
90330 7150 3-Feb-11 Replace The Front Lights
91010 7150 3-Feb-11 Replace The Break Lights
91210 7150 3-Feb-11 Na
90770 7150 3-Feb-11 Fixed The Horn System
90450 7150 4-Feb-11 Fixed The Break System
90970 7150 4-Feb-11 Na
90610 7000 31-Jan-11
90570 7000 31-Jan-11
61
63. /* Manager wants to know the name of clients who made request */
select c.customer_id, first_name||','|| last_name as client, v.request_date, v.request_type, v.service_option
from "customer" c inner join "reservations" v on c.customer_id = v.customer_id where v.request_type = 'car sale';
CUSTOMER_ID CLIENT REQUEST_DATE REQUEST_TYPE SERVICE_OPTION
90810 Joshua,Randall 31-Jan-11 car sale
91010 Linda,Kobara 31-Jan-11 car sale
91130 Salman,Mughal 31-Jan-11 car sale
90170 Tyson,Haywood 1-Feb-11 car sale
90410 Latifah,msxwall 1-Feb-11 car sale
91170 Paul,Born 2-Feb-11 car sale
90970 Joseph,Matthews 2-Feb-11 car sale
/* manager wants to know which mechanic fixed which car including the model*/
62
64. select m.mechanic_id, m.first_name||','||m.last_name as Mechnaic, c.model, c.car_Id, r.repair_id from "mechanic" m inner join
"repair record" r on m.mechanic_id = r.mechanic_id inner join "car" c on c.car_id = r.car_id;
MECHANIC_ID MECHNAIC CAR_MODEL CAR_ID REPAIR_ID
7000 Johnnattan,Bryon 2010 2036 2416
7120 Hendron,D.Mario 2011 2040 2624
7000 Johnnattan,Bryon 2010 2036 3664
7120 Hendron,D.Mario 2010 2038 4912
7150 Justice,Mario 2010 2036 6160
/* Manager wants to know the cost of each repair services*/
select m.first_name as Mechnaic, c.model, c.car_Id, r.repair_id, to_char( r.amount_charged,'$999,999.99') as Charge_Amount,
to_char(r.CASH, '$9999,999.99') as Cash from "mechanic" m inner join repairrecord r on m.mechanic_id = r.mechanic_id inner
join "car" c on c.car_id = r.car_id;
MECHNAIC MODEL CAR_ID REPAIR_ID CHARGE_AMOUNT CASH
Johnnattan 2010 2036 2416 $70.99 $70.99
Hendron 2011 2040 2624 $90.99 $90.99
Johnnattan 2010 2036 3664 $70.99 $70.99
Hendron 2010 2038 4912 $490.99 $490.99
63
65. justice 2010 2036 6160 $50.00 $50.00
/* Manager wants to know the total cost of repair service*/
select to_char(sum(amount_charged), '$999,999.99')as Repair_Total from repairrecord;
REPAIR_TOTAL
------------
$2,831.85
/* Manager wants to know total repair cost daily *. To get the right first query the database for repair date/
select repair_id, repair_date, to_char(amount_charged,'$9999,999.99') as Amount_charged, to_char(cash, '$9999,999.99') as Cash,
sum( cash )
over( partition by repair_date) as Repair_Toatl_Amount_daily
from repairrecord
REPAIR_ID REPAIR_DATE AMOUNT_CHARGED CASH REPAIR_TOATL_AMOUNT_DAILY
4496 1-Feb-11 $110.99 $110.99 293.96
4288 1-Feb-11 $40.99 $40.99 293.96
4080 1-Feb-11 $70.99 $70.99 293.96
64
67. /* Manager want to know the amount paid total by check without renaming balance*/
select to_char(sum(amount_paid_check), '$999,999.99')as Check_total from CarSales where remaning_amount = 0;
CHECK_TOTAL
------------
$55,000.00
/* Manager want to know the amount paid total by loan without renaming balance*/
select to_char(sum(amount_paid_loan), '$999,999.99')as Loan_total from CarSales where remaning_amount = 0;
LOAN_TOTAL
------------
$0.00
/* Manager want to know the amount paid total by loan*/
select to_char(sum(amount_paid_loan), '$999,999.99')as Loan_total from CarSales ;
LOAN_TOTAL
66
68. ------------
$114,060.00
/* Manager want to know which agent sold a car */
select a.agent_id,a.car_id, c.model, initcap (c.maker) as Maker, initcap (b.first_name||','||b.last_name) as agent
from CarSales a inner join "car" c on a.car_id = c.car_id inner join "agent" b on b.agent_id = a.agent_id order by maker;
AGENT_ID CAR_ID MODEL MAKER AGENT
8316 2006 2008 Ford Maryanne,Stephine
8158 2002 2009 Ford Chris,Paul
8158 2022 2011 Honda Chris,Paul
8316 2034 2011 Honda Maryanne,Stephine
8158 2028 2011 Hyndai Chris,Paul
8237 2040 2011 Hyndai Melisa,Henwood
8316 2032 2009 Hyndai Maryanne,Stephine
8079 2030 2010 Hyndai Dolly,Chris
8000 2010 2004 Toyota Celin,Doveward
8079 2012 2003 Toyota Dolly,Chris
/*Manager wants to include transaction id and sales date to the previous report*/
67
69. select a.agent_id,a.car_id, a.transaction_id, a.sales_date, c.model, initcap (c.maker) as Maker, initcap (b.first_name||','||
b.last_name) as agent
from CarSales a inner join "car" c on a.car_id = c.car_id inner join "agent" b on b.agent_id = a.agent_id order by maker;
AGENT_ID CAR_ID TRANSACTION_ID SALES_DATE MODEL MAKER AGENT
8316 2006 900266 1-Feb-11 2008 Ford Maryanne,Stephine
8158 2002 900711 3-Feb-11 2009 Ford Chris,Paul
8158 2022 900088 31-Jan-11 2011 Honda Chris,Paul
8316 2034 900355 1-Feb-11 2011 Honda Maryanne,Stephine
8158 2028 900800 4-Feb-11 2011 Hyndai Chris,Paul
8237 2040 900444 2-Feb-11 2011 Hyndai Melisa,Henwood
8316 2032 900533 2-Feb-11 2009 Hyndai Maryanne,Stephine
8079 2030 900177 31-Jan-11 2010 Hyndai Dolly,Chris
8000 2010 900622 3-Feb-11 2004 Toyota Celin,Doveward
8079 2012 899999 31-Jan-11 2003 Toyota Dolly,Chris
* Manager wants to create table to hold the previous report for easy access*
create table "report" as
select a.agent_id,a.car_id, a.transaction_id, a.sales_date, c.model, initcap (c.maker) as Maker, initcap (b.first_name||','||
b.last_name) as agent
68
70. from CarSales a inner join "car" c on a.car_id = c.car_id inner join "agent" b on b.agent_id = a.agent_id order by maker;
select * from "report";
AGENT_ID CAR_ID TRANSACTION_ID SALES_DATE MODEL MAKER AGENT
8316 2006 900266 1-Feb-11 2008 Ford Maryanne,Stephine
8158 2002 900711 3-Feb-11 2009 Ford Chris,Paul
8158 2022 900088 31-Jan-11 2011 Honda Chris,Paul
8316 2034 900355 1-Feb-11 2011 Honda Maryanne,Stephine
8158 2028 900800 4-Feb-11 2011 Hyndai Chris,Paul
8237 2040 900444 2-Feb-11 2011 Hyndai Melisa,Henwood
8316 2032 900533 2-Feb-11 2009 Hyndai Maryanne,Stephine
8079 2030 900177 31-Jan-11 2010 Hyndai Dolly,Chris
8000 2010 900622 3-Feb-11 2004 Toyota Celin,Doveward
8079 2012 899999 31-Jan-11 2003 Toyota Dolly,Chris
/* Manager wants to know which of their clients from East Chicago and BlueIsland who bought a car to mail them special
discounts*/
select b.customer_id, INITCAP(b.city) AS CITY,
a.car_id, a.transaction_id, a.sales_date, c.model, initcap (c.maker) as Maker, initcap (b.first_name||','||
b.last_name) as Customer
from "customer" b inner join carsales a
on
b.customer_id = a.customer_id
inner join "car" c
69
71. on
a.car_id = c.car_id
where city ='blueisland' or city = 'East Chicago'
CUSTOMER_ID CITY CAR_ID TRANSACTION_ID SALES_DATE MODEL MAKER CUSTOMER
91010 East Chicago 2022 900088 31-Jan-11 2011 Honda Linda,Kobara
91250 Blueisland 2034 900355 1-Feb-11 2011 Honda Tim ,O-Brien
91250 Blueisland 2040 900444 2-Feb-11 2011 Hyndai Tim ,O-Brien
91010 East Chicago 2028 900800 4-Feb-11 2011 Hyndai Linda,Kobara
/* Manager wants to know which of their clients from IL who bought a car to give them a call for discounts*/
select b.customer_id, INITCAP(b.city) AS CITY,
a.car_id, a.transaction_id, a.sales_date, c.model, initcap (c.maker) as Maker, initcap (b.first_name||','||
b.last_name) as Customer
from "customer" b inner join carsales a
on
b.customer_id = a.customer_id
inner join "car" c
on
70
72. a.car_id = c.car_id
where CUST_STATE in (‘IL’, ‘il’,’Il’)
CUSTOMER_ID CITY CAR_ID TRANSACTION_ID SALES_DATE MODEL MAKER CUSTOMER
91170 University 2006 900266 1-Feb-11 2008 Ford Paul,Born
Park
91170 University 2032 900533 2-Feb-11 2009 Hyndai Paul,Born
Park
91250 Blueisland 2034 900355 1-Feb-11 2011 Honda Tim ,O-Brien
91250 Blueisland 2040 900444 2-Feb-11 2011 Hyndai Tim ,O-Brien
/* Manager wants to know which of their clients from IN who bought a car to give them a call for discounts*/
select b.customer_id, INITCAP(b.city) AS CITY,
a.car_id, a.transaction_id, a.sales_date, c.model, initcap (c.maker) as Maker, initcap (b.first_name||','||
b.last_name) as Customer
from "customer" b inner join carsales a
on
b.customer_id = a.customer_id
inner join "car" c
on
71
73. a.car_id = c.car_id
where CUST_STATE in ('IN', 'in', 'In');
CUSTOMER_ID CITY CAR_ID TRANSACTION_ID SALES_DATE MODEL MAKER CUSTOMER
90890 Indiana City 2002 900711 3-Feb-11 2009 Ford Kathryn,Wilson
90970 St John 2010 900622 3-Feb-11 2004 Toyota Joseph,Matthews
90810 Indiana City 2012 899999 31-Jan-11 2003 Toyota Joshua,Randall
91010 East Chicago 2022 900088 31-Jan-11 2011 Honda Linda,Kobara
91010 East Chicago 2028 900800 4-Feb-11 2011 Hyndai Linda,Kobara
91130 Gary 2030 900177 31-Jan-11 2010 Hyndai Salman,Mughal
/* Manager wants to know how many reservations has been made*/
select request_id , request_date, request_time, service_option
from "reservations"
where exists(select customer_id, first_name from "customer")
72