Question

In: Computer Science

Assume that the following relationships were created in a database. CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone) COURSE...

Assume that the following relationships were created in a database.

CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone)

COURSE (CourseNumber, CourseTitle, TeachingMode, CourseCreationDate, Fee)

ENROLLMENT (EnrollmentID, CustomerNumber, CourseNumber, EnrollmentDate, AmountPaid)

Legend:
Primary Key

Foreign Key

Possible values

TeachingMode: PRE - Presencial, ONL - Online


Write the SQL (ORACLE) statements required to complete what is required below. Provide ONE instruction per request / question. Write your answers in the space provided. Identify each answer with the corresponding request / question number.

1. Create the CUSTOMER table include the constraints 
2. Create the COURSE table include the constraints 
3. Create the ENROLLMENT table include the constraints 
4. Create the sequence seqEnroll 
5. Insert a row in the CUSTOMER table. 
6. Insert a row in the COURSE table. 
7. Insert a row in the ENROLLMENT table. The primary key field is a substitute (Surrogate / Artificial) so it will use the sequence you created in statement 4. The transaction must belong to the CUSTOMER you created in # 5 and the COURSE you created in # 6. 
8. List customers in ascending alphabetical order by last name. Include the following information in this order: last name, first name and telephone number 
9. List all the courses that have the word Pastels in the title. Include all the data in the COURSE table. 
10. List all the courses the clients are enrolled in. Include the following data in this order: CustomerNumber, CourseNumber, and AmountPaid. 
11. List all courses that started on or before October 1, 2018. Include the following data in this order: CourseDate, CourseNumber, CourseTitle, Fee. 
12. Show for each client the total paid for classroom courses and total paid for online courses TeachingMode the total paid by each client. 
Show courses that are cheaper than the average price Use subquery and functions. 
13. List all course information if you have had at least ten clients enrolled in the past twelve months. It must work at any time, the twelve-month period will depend on the date the consultation is run. DO NOT USE SPECIFIC DATES. Use subquery and functions.

Solutions

Expert Solution

Assuming the schema name as CD. If schema name is different then replace CD with that.

1. CREATE TABLE CD.CUSTOMER (
    CustomerNumber VARCHAR2(50) NOT NULL,
    CustomerLastName VARCHAR2(50) NOT NULL,
    CustomerFirstName VARCHAR2(50) NOT NULL,
    Phone VARCHAR2(50) NOT NULL,
PRIMARY KEY (CustomerNumber)
);

2. CREATE TABLE CD.COURSE(
    CourseNumber VARCHAR2(50) NOT NULL,
    CourseTitle VARCHAR2(50) NOT NULL,
    TeachingMode VARCHAR2(50) NOT NULL,
    CourseCreationDate DATE,
    Fee NUMBER(7,2) NOT NULL,
PRIMARY KEY (CourseNumber)
);

3. CREATE TABLE CD.COURSE(
    EnrollmentID NUMBER(5) NOT NULL,
    CustomerNumber VARCHAR2(50) NOT NULL,
    CourseNumber VARCHAR2(50) NOT NULL,
    EnrollmentDate DATE,
    AmountPaid NUMBER(7,2),
PRIMARY KEY (EnrollmentID)
FOREIGN KEY (CustomerNumber) REFERENCES CUSTOMER(CustomerNumber),
FOREIGN KEY (CourseNumber) REFERENCES COURSE(CourseNumber)
);

4. CREATE SEQUENCE seqEnroll
START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

5. INTO CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone) VALUES ('CUST001','Joseph', 'Alex','+110023883')
INTO CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone) VALUES ('CUST002','Newton', 'Issac','+110023865')
INTO CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone) VALUES ('CUST003','Einstein', 'Albert','+110023844')
SELECT * FROM dual;

6. INSERT ALL
INTO COURSE(CourseNumber, CourseTitle, TeachingMode, CourseCreationDate, Fee) VALUES ('COUR001','CSE', 'ONL','01-APR-2017')
INTO CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone) VALUES ('CUST002','ECE', 'ONL','01-AUG-2019')
INTO CUSTOMER (CustomerNumber, CustomerLastName, CustomerFirstName, Phone) VALUES ('CUST003','MECH', 'PRE','01-AUG-2018')
SELECT * FROM dual;

7. INSERT INTO ENROLLMENT(EnrollmentID, CustomerNumber, CourseNumber, EnrollmentDate, AmountPaid) VALUES (seqEnroll.nextval,'CUST001', 'COUR001','01-AUG-2018',500);

8. SELECT
CustomerLastName, CustomerFirstName, Phone
FROM
CUSTOMER ORDER BY CustomerLastName ASC;

9. SELECT *
FROM
COURSE WHERE CourseTitle LIKE '%Pastels%';

10. SELECT
CustomerNumber, CourseNumber, AmountPaid
FROM ENROLLMENT
INNER JOIN CUSTOMER USING(CustomerNumber)
INNER JOIN COURSE USING(CourseNumber);

11. SELECT
CourseDate, CourseNumber, CourseTitle, Fee
FROM COURSE
WHERE CourseCreationDate<='October 1, 2018';

12. Function Created

CREATE OR REPLACE FUNCTION get_CheaperCource (avg_fee)
RETURN VARCHAR
IS
courseName VARCHAR(50) := NULL;
BEGIN
FOR courceNme IN (SELECT CourseTitle FROM COURSE WHERE FEE< avg_fee) LOOP
courseName := courseName || ',' || courceNme.CourseTitle;
END LOOP;
RETURN LTRIM(courseName, ',');
END;

Select Query

SELECT
CustomerLastName, CustomerFirstName , CourseTitle, TeachingMode, AmountPaid,
get_CheaperCource(AVG(Fee)) AS CourseTitle
FROM ENROLLMENT
INNER JOIN CUSTOMER USING(CustomerNumber)
INNER JOIN COURSE USING(CourseNumber);

13. SELECT (SELECT CourseTitle FROM COURSE WHERE CourseNumber = ENROLLMENT.CustomerNumber) AS CourseTitle,
(SELECT TeachingMode FROM COURSE WHERE CourseNumber = ENROLLMENT.CustomerNumber) AS TeachingMode,
(SELECT Fee FROM COURSE WHERE CourseNumber = ENROLLMENT.CustomerNumber) AS Fee
FROM ENROLLMENT WHERE CourseTitle IN
(SELECT CourseTitle from ENROLLMENT GROUP BY CourseTitle HAVING COUNT(CourseTitle) >=10 AND EnrollmentDate BETWEEN TO_DATE (TO_CHAR(SYSDATE), 'yyyy/mm/dd'))
BETWEEN ADD_MONTHS(TRUNC(sysdate, 'month'), -12) and TRUNC(sysdate, 'month')


Related Solutions

A database schema consisting of three relations STUDENT, COURSE, and STAFF is created as follows: CREATE...
A database schema consisting of three relations STUDENT, COURSE, and STAFF is created as follows: CREATE TABLE STUDENT (STU_ID CHAR(4), STUDENT_NAME CHAR(20), ADDRESS CHAR(20), BIRTHDATE DATE, GENDER CHAR(6)); CREATE TABLE COURSE (COURSE_ID CHAR(6), COURSE_TITLE CHAR(20), STAFF_ID CHAR(3), SECTION NUMBER(2)); CREATE TABLE STAFF (STAFF_ID CHAR(3), STAFF_NAME CHAR(20), GENDER CHAR(6), DEPARTMENT CHAR(20), BOSS_ID CHAR(3) SALARY NUMBER(8,2)); Write down SQL statement for each query below: 1) Find out the information of staff members who are female and earn either below $5,000 or above...
There are many kinds of entity relationships in a database model. The relationships can be classified by the following things.
There are many kinds of entity relationships in a database model. The relationships can be classified by the following things.Cardinality: maximum and minimumDegree: binary, ternary, degree 4, and so forthEntity type: strong, weak, ID-dependent, and supertype or subtypeWhat are these different types of classifications? Do they overlap, or do they each tell us something unique about the entity relationship? Why is it important to classify each of these types in an ERD model?
The following data represent the monthly phone​ use, in​ minutes, of a customer enrolled in a...
The following data represent the monthly phone​ use, in​ minutes, of a customer enrolled in a fraud prevention program for the past 20 months. The phone company decides to use the upper fence as the cutoff point for the number of minutes at which the customer should be contacted. 446, 363, 488, 329, 468, 304, 444, 459, 336, 415, 403, 542, 473, 448, 531, 355, 451, 547, 465, 334 What is the cutoff​ point?
The following data represent the monthly phone​ use, in​ minutes, of a customer enrolled in a...
The following data represent the monthly phone​ use, in​ minutes, of a customer enrolled in a fraud prevention program for the past 20 months. The phone company decides to use the upper fence as the cutoff point for the number of minutes at which the customer should be contacted. What is the cutoff​ point? 397 391 401 438 342 518 516 335 301 347 500 388 325 422 510 434 541 303 321 345 The cutoff point is minutes.
Assume you are given the following relationships for the Haslam Corporation
Assume you are given the following relationships for the Haslam Corporation: Sales/total assets 1.3 Return on assets (ROA) 3% Return on equity (ROE) 7% Calculate Haslam's profit margin. Do not round intermediate calculations. Round your answer to two decimal places. 2.31 % Calculate Haslam's liabilities-to-assets ratio. Do not round intermediate calculations. Round your answer to two decimal places. % Suppose half of Haslam's liabilities are in the form of debt. Calculate the debt-to-assets ratio. Do not round intermediate calculations. Round...
Argue for or against the following statement: “In the electronic age, customer relationships are more important...
Argue for or against the following statement: “In the electronic age, customer relationships are more important than ever, and Zappos provides the new benchmark that all corporations should follow.”
For the given database schema. Answer the following questions. Company Database customer(cust_id, name, address) product(product_id, product_name,...
For the given database schema. Answer the following questions. Company Database customer(cust_id, name, address) product(product_id, product_name, price, quantity) transaction(trans_id, cust_id, time_date) product_trans(product_id, trans_id) Identify the primary keys and foreign keys for the relations and specify at least two different types of integrity constraints that would be applicable for different relations given.
1. How many 12-digit phone numbers can be created with the following restrictions: a) no restrictions...
1. How many 12-digit phone numbers can be created with the following restrictions: a) no restrictions b) first number cannot be zero or one. c) no repeated numbers 2. Find the number of distinguishable permutations of the letters in the following words. a) CALCULUS b) PEPPER c) MISSISSIPPI
Building and maintaining profitable customer relationships by delivering superior customer value and satisfaction is called ________....
Building and maintaining profitable customer relationships by delivering superior customer value and satisfaction is called ________. Select one: a. partner relationship management b. customer-perceived value c. customer lifetime value d. customer relationship management e. customer equity
2. Describe the recommended procedures for improving customer-to-customer relationships during a service encounter.
2. Describe the recommended procedures for improving customer-to-customer relationships during a service encounter.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT