I need help for SQL homework.
the question:
the code for part 1,2:
drop table Customer;
drop table Company;
drop table Cruise;
drop table TravelAgent;
drop table Reservation;
drop sequence customerID_seq;
drop sequence cruiseID_seq;
drop sequence travelAgentID_seq;
drop sequence reservationID_seq;
create table Customer(
customerID number,
firstName varchar2(15),
lastName varchar2(15),
address varchar2(30),
phone number(10) not null,
age number(3),
Constraint Customer_PK Primary Key (customerID),
constraint Customer_unique unique (firstName,lastName,phone),
constraint Customer_check check(phone is not null)
);
create sequence customerID_seq
start with 1
increment by 1;
insert into Customer values (customerID_seq.nextval, 'Dylan',
'Ward', '42 Elm Place', 8915367188, 22);
insert into Customer values (customerID_seq.nextval, 'Austin',
'Ross', '657 Redondo Ave.', 1233753684, 25);
insert into Customer values (customerID_seq.nextval, 'Lisa',
'Powell', '5 Jefferson Ave.', 6428369619, 17);
insert into Customer values (customerID_seq.nextval, 'Brian',
'Martin', '143 Cambridge Ave.', 5082328798, 45);
insert into Customer values (customerID_seq.nextval, 'Nicole',
'White', '77 Massachusetts Ave.', 6174153059, 29);
insert into Customer values (customerID_seq.nextval, 'Tyler',
'Garcia', '175 Forest St.', 9864752346, 57);
insert into Customer values (customerID_seq.nextval, 'Anna',
'Allen', '35 Tremont St.', 8946557732, 73);
insert into Customer values (customerID_seq.nextval, 'Michael',
'Sanchez', '9 Washington Court', 1946825344, 18);
insert into Customer values (customerID_seq.nextval, 'Justin',
'Myers', '98 Lake Hill Drive', 7988641411, 26);
insert into Customer values (customerID_seq.nextval, 'Bruce',
'Clark', '100 Main St.', 2324648888, 68);
insert into Customer values (customerID_seq.nextval, 'Rachel',
'Lee', '42 Oak St.', 2497873464, 19);
insert into Customer values (customerID_seq.nextval, 'Kelly',
'Gray', '1414 Cedar St.', 9865553232, 82);
insert into Customer values (customerID_seq.nextval, 'Madison',
'Young', '8711 Meadow St.', 4546667821, 67);
insert into Customer values (customerID_seq.nextval, 'Ashley',
'Powell', '17 Valley Drive', 2123043923, 20);
insert into Customer values (customerID_seq.nextval, 'Joshua',
'Davis', '1212 8th St.', 7818914567, 18);
select * from Customer;
create table Company(
companyName varchar2(15),
stockSymbol char(4),
website varchar2(40),
Constraint Company_PK Primary Key (companyName),
Constraint Company_Uni unique(stockSymbol)
);
insert into Company values ('Carnival', 'CRVL',
'http://www.carnival.com');
insert into Company values ('Celebrity', 'CELB',
'http://www.celebritycruises.com');
insert into Company values ('NCL', 'NCLC',
'http://www.ncl.com');
insert into Company values ('Princess', 'PRCS',
'http://www.princess.com');
select * from Company;
create table Cruise(
cruiseID number,
cruiseName varchar2(25),
departurePort varchar2(20),
days number(2),
companyName varchar2(15),
shipName varchar2(30),
price number(7,2),
Constraint Cruise_PK Primary Key (cruiseID),
Constraint Cruise_companyName_FK Foreign Key (companyName)
References Company(companyName) ON DELETE CASCADE
);
create sequence cruiseID_seq
start with 1
increment by 1;
insert into Cruise values (cruiseID_seq.nextval, 'Mexico',
'Miami', 7 , 'NCL', 'Norwegian Pearl', 799.00);
insert into Cruise values (cruiseID_seq.nextval, 'New England',
'Boston', 7 , 'NCL', 'Norwegian Pearl', 895.75);
insert into Cruise values (cruiseID_seq.nextval, 'ABC Islands',
'Miami', 4 , 'Celebrity', 'Equinox', 450.50);
insert into Cruise values (cruiseID_seq.nextval, 'Hawaii', 'San
Francisco', 14 , 'Princess', 'Crown Princess', 2310.00);
insert into Cruise values (cruiseID_seq.nextval, 'Panama Canal',
'Miami', 10 , 'Carnival', 'Carnival Spirit', 1432.99);
select * from Cruise;
create table TravelAgent(
travelAgentID number,
firstname varchar2(15),
lastname varchar2(20),
title varchar2(15),
salary number(7,2),
constraint TravelAgent_Pk primary key(travelAgentID),
constraint check_title check(title in
('Agent','Manager','Assistant'))
);
create sequence travelAgentID_seq
start with 1
increment by 1;
insert into TravelAgent values (travelAgentID_seq.nextval,
'Chloe', 'Rodriguez', 'Assistant' , 31750.00);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Ben',
'Wilson', 'Agent' , 47000.22);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Mia',
'Smith', 'Manager' , 75250.00);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Noah',
'Williams', 'Assistant' , 32080.90);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Liam',
'Brown', 'Manager' , 60500.75);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Mason',
'Jones', 'Manager', 79000.00);
insert into TravelAgent values (travelAgentID_seq.nextval,
'Olivia', 'Miller', 'Agent' , 54000.50);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Sofia',
'Davis', 'Agent' , 45000.00);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Jason',
'Garcia', 'Manager' , 52025.95);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Emily',
'Johnson', 'Assistant' , 22000.50);
insert into TravelAgent values (travelAgentID_seq.nextval, 'Ethan',
'Elm', 'Agent' , 27044.52);
select * from TravelAgent;
create table Reservation(
reservationID number,
customerID number,
cruiseID number,
travelAgentID number,
travelDate date,
constraint Reservation_customerID_PK primary key
(reservationID),
Constraint Reservation_customerID_FK Foreign Key (customerID)
References Customer (customerID) ON DELETE CASCADE ,
Constraint Reservation_cruiseID_FK Foreign Key (cruiseID)
References Cruise (cruiseID) ON DELETE CASCADE,
Constraint Reservation_travelAgentID_FK Foreign Key (travelAgentID)
References TravelAgent (travelAgentID) ON DELETE CASCADE
);
create sequence reservationID_seq
start with 1
increment by 1;
insert into Reservation values (reservationID_seq.nextval, 12,
1, 2, '9-Nov-18');
insert into Reservation values (reservationID_seq.nextval, 14, 4,
5, '21-Jan-19');
insert into Reservation values (reservationID_seq.nextval, 5, 4, 1,
'11-Dec-18');
insert into Reservation values (reservationID_seq.nextval, 9, 5, 4,
'31-Aug-19');
insert into Reservation values (reservationID_seq.nextval, 13, 1,
2, '10-Apr-19');
insert into Reservation values (reservationID_seq.nextval, 5, 4, 6,
'29-Jul-18');
insert into Reservation values (reservationID_seq.nextval, 2, 2, 2,
'17-May-19');
insert into Reservation values (reservationID_seq.nextval, 4, 1,
10, '11-Apr-19');
insert into Reservation values (reservationID_seq.nextval, 10, 5,
3, '3-Jun-18');
insert into Reservation values (reservationID_seq.nextval, 5, 3, 9,
'15-Oct-18');
insert into Reservation values (reservationID_seq.nextval, 1, 2, 7,
'8-Mar-19');
insert into Reservation values (reservationID_seq.nextval, 5, 4, 7,
'24-Nov-18');
insert into Reservation values (reservationID_seq.nextval, 8, 1, 1,
'3-Aug-19');
insert into Reservation values (reservationID_seq.nextval, 15, 5,
10, '13-Dec-18');
insert into Reservation values (reservationID_seq.nextval, 4, 3, 7,
'6-Feb-19');
insert into Reservation values (reservationID_seq.nextval, 6, 4, 5,
'12-Aug-19');
insert into Reservation values (reservationID_seq.nextval, 14, 2,
8, '22-Jun-19');
insert into Reservation values (reservationID_seq.nextval, 11, 5,
9, '1-Feb-19');
insert into Reservation values (reservationID_seq.nextval, 7, 4, 8,
'15-Mar-19');
insert into Reservation values (reservationID_seq.nextval, 14, 4,
3, '28-Feb-19');
select * from Reservation;
a.
Select distinct companyName , crusieName from Company inner join Cruise on Company.CompayName = Cruise.CompanyName inner join Reservation on Cruise.CruiseID = Reservation.CruiseID inner join Customer on Reservation.CustomerID = Customer.CustomerID where age > 50 and departurePort = 'Miami' order by companyName ;
b.
Select companyName||StockSymbol as CruiseCompany , cruiseName, travelDate from Company natural join Cruise natural join Reservation where year(travelDate) > 2018 and days >= 10 order by cruiseName,travelDate;
Do ask if any doubt. Please upvote.
I need help for SQL homework. the question: the code for part 1,2: drop table Customer;...
-- drop tables DROP TABLE REQUEST CASCADE CONSTRAINTS; DROP TABLE FULLORDER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; -- create and link tables CREATE TABLE CUSTOMER ( CustomerID INTEGER, Name VARCHAR2(40), City VARCHAR2(20), State CHAR(2), Zip CHAR(5), CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustomerID) ); CREATE TABLE PRODUCT ( ProductID INTEGER, Description VARCHAR2(30), Material VARCHAR2(20), Price NUMBER(5,2), CONSTRAINT PK_PRODUCT...
-- drop tables DROP TABLE REQUEST CASCADE CONSTRAINTS; DROP TABLE FULLORDER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; -- create and link tables CREATE TABLE CUSTOMER ( CustomerID INTEGER, Name VARCHAR2(40), City VARCHAR2(20), State CHAR(2), Zip CHAR(5), CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustomerID) ); CREATE TABLE PRODUCT ( ProductID INTEGER, Description VARCHAR2(30), Material VARCHAR2(20), Price NUMBER(5,2), CONSTRAINT PK_PRODUCT...
Here is the P4 university database ---Drop tables --Drop Table FACULTY Cascade Constraints; --Drop Table OFFERING Cascade Constraints; --Drop Table STUDENT Cascade Constraints; --Drop Table COURSE Cascade Constraints; --Drop Table ENROLLMENT Cascade Constraints; Create Table STUDENT( Std_ID NUMBER(3) Constraint Student_STD_ID_FK PRIMARY KEY, Std_FN Varchar2 (9), Std_LN Varchar2 (8) , Std_City Varchar2 (10), Std_State Varchar2 (4), Std_Zip Number (5), Std_Major Varchar2 (6), Std_Class Varchar2 (3), Std_GPA NUMBER (3,2)); ---Insert records into Student Insert Into STUDENT Values( 101, 'Joe', 'Smith','Eau Clare','WI',18121,'IS','FR',3.8); Insert...
Write a pl/sql block of code that will make a reservation for a customer for any destination. The destination id, number of peolpe going and date will be entered by the user. Your code should calculate the cost and enter the data in the sales table. No destination can have more than 10 people going during the same dates. If the number is greater than 10 raise 'Sold_out' exception and print a message 'Sorry we are sold out for ths...
oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DROP TABLE BOOKS; DROP TABLE PROMOTION; DROP TABLE AUTHOR; DROP TABLE CUSTOMERS; DROP TABLE PUBLISHER; CREATE TABLE Customers ( Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Email VARCHAR(40), Address VARCHAR2(20), City VARCHAR2(12), State VARCHAR2(2), Zip VARCHAR2(5), Referred NUMBER(4), Region CHAR(2), CONSTRAINT customers_customer#_pk PRIMARY KEY(customer#) ); INSERT INTO CUSTOMERS VALUES (1001, 'MORALES', 'BONITA', '[email protected]', 'P.O. BOX 651', 'EASTPOINT', 'FL', '32328', NULL, 'SE'); INSERT INTO CUSTOMERS VALUES...
I need help with the following SQL query for a company database (script given below). The name of the Department. The number of employees working in that department. The number of different projects controlled by this department. The name of the project controlled by this department that has the maximum number of employees of the company working on it. The number of the above project. The cumulative sum of the number of employees of the company working on the projects...
drop table department cascade constraints; create table department ( Dname varchar2(15) not null, Dnumber int not null, Mgr_ssn char(9) not null, mgr_start_date Date, primary key (Dnumber), Unique (Dname)); insert into DEPARTMENT values ('Research', '5', '333445555', '22-May-1988'); insert into DEPARTMENT values ('Administration', '4', '987654321', '01-Jan-1995'); insert into DEPARTMENT values ('Headquarters', '1', '888665555', '19-Jun-1981'); drop table employee cascade constraints; create table employee ( Fname varchar2(15) not null, Minit char(1), Lname varchar2(15) not null, Ssn char(9), Bdate date, Address varchar2(30), Sex char(1),...
I am using oracle sql developer to create some queries to generated reports and it is not working. I am not sure how to use count, group by, and order by. Help me fix my query and explain to me how you did, so can do it next time. Also, I have to convert this query to a stored procedure, so can you help me do it too? Here is my query: SELECT COUNT(GUEST.FIRSTNAME), GUEST.FIRSTNAME, GUEST.LASTNAME, GUEST.GUESTTYPE, RESERVATION.RESERVATIONDATE, GUEST.EMAIL, FROM...
DROP TABLE IF EXISTS customers; DROP TABLE IF EXISTS orders; DROP TABLE IF EXISTS order_details; DROP TABLE IF EXISTS items; DROP TABLE IF EXISTS artists; DROP TABLE IF EXISTS employees; -- create tables CREATE TABLE customers ( customer_id INT , customer_first_name VARCHAR(20), customer_last_name VARCHAR(20) NOT NULL, customer_address VARCHAR(50) NOT NULL, customer_city VARCHAR(20) NOT NULL, customer_state CHAR(2) NOT NULL, customer_zip CHAR(5) NOT NULL, customer_phone CHAR(10) NOT NULL, customer_fax CHAR(10), CONSTRAINT customers_pk...
I need the SQL code to accomplish the following: Provide a list of orders that were created in January 2013. Be sure to show the order number, date, employee name who took the order, and customer name who created the order. For all of the orders for 17” monitors in 2013, provide a list that shows the order number, date, and the quantity. here is the database CREATE DATABASE OrderEntryBMIS325 GO USE OrderEntryBMIS325 GO CREATE TABLE Customer ( CustNo CHAR(8),...