You are on page 1of 8

CCS0021 LABORATORY

TECHNICAL ASSESSMENT

Part 1:

Instructions: Using the diagram below, write the DDL code to create the following entities into tables.
The relationships of the tables should also be written on the code. You can use SQL developer to solve
this. Copy and paste the codes below. Save the SQL scripts as Tech6_fullname. Save this document as
Tech2Document_fullname.

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
CREATE TABLE tasks (

idtask INTEGER NOT NULL,


name VARCHAR2(45) NOT NULL,
description VARCHAR2(4000) NOT NULL,
work VARCHAR2(45) NOT NULL,
startdate DATE NOT NULL,
enddate DATE NOT NULL,
createdat DATE NOT NULL,
updatedat DATE NOT NULL,
enabled CHAR(1) NOT NULL
);

ALTER TABLE tasks ADD CONSTRAINT tasks_pk PRIMARY KEY ( idtask );

CREATE TABLE timecategory (


idtimecategory INTEGER NOT NULL,
name VARCHAR2(45) NOT NULL,
description VARCHAR2(4000) NOT NULL,
createdat DATE NOT NULL,
updatedat DATE NOT NULL,
enabled CHAR(1) NOT NULL
);

ALTER TABLE timecategory ADD CONSTRAINT timecategory_pk PRIMARY KEY ( idt


imecategory );

CREATE TABLE timesheet


( idtimesheet INTEGER NOT
NULL,
name VARCHAR2(45) NOT NULL,
description VARCHAR2(4000) NOT NULL,
idproject INTEGER NOT NULL,
createdat DATE NOT NULL,
updatedat DATE NOT NULL,
enabled CHAR(1) NOT NULL,
iduser INTEGER,
FOREIGN KEY (iduser) REFERENCES User(iduser)
);

ALTER TABLE timesheet ADD CONSTRAINT timesheet_pk PRIMARY KEY ( idtimeshe


et );

CREATE TABLE timesheethour (


idtimesheethour INTEGER NOT NULL,
quantity INTEGER NOT NULL,

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
description VARCHAR2(4000) NOT NULL,
user_iduser INTEGER NOT NULL,
tasks_idtask INTEGER NOT NULL,
timecategory_idtimecategory INTEGER NOT NULL,
timesheet_idtimesheet INTEGER NOT NULL
);

ALTER TABLE timesheethour ADD CONSTRAINT timesheethour_pk PRIMARY KEY ( i


dtimesheethour );

CREATE TABLE "User" (


iduser INTEGER NOT NULL,
name VARCHAR2(45) NOT NULL,
lastname VARCHAR2(45) NOT NULL,
email VARCHAR2(255) NOT NULL,
username VARCHAR2(25) NOT NULL,
password CHAR(60) NOT NULL,
createdat DATE NOT NULL,
updatedat DATE NOT NULL,
enabled CHAR(1) NOT NULL
);

ALTER TABLE "User" ADD CONSTRAINT user_pk PRIMARY KEY ( iduser );

ALTER TABLE timesheethour


ADD CONSTRAINT timesheethour_tasks_fk FOREIGN KEY ( tasks_idtask )
REFERENCES tasks ( idtask );

ALTER TABLE timesheethour


ADD CONSTRAINT timesheethour_timecategory_fk FOREIGN KEY ( timecatego
ry_idtimecategory )
REFERENCES timecategory ( idtimecategory );

ALTER TABLE timesheethour


ADD CONSTRAINT timesheethour_timesheet_fk FOREIGN KEY ( timesheet_idt
imesheet )
REFERENCES timesheet ( idtimesheet );

ALTER TABLE timesheethour


ADD CONSTRAINT timesheethour_user_fk FOREIGN KEY ( user_iduser )
REFERENCES "User" ( iduser );

Part 2:

Answer the following numbers using the table given. Use SQL developer to solve this.

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
Save the SQL script as: Tech7_fullname. Make sure you make the questions in the worksheet as
comments.

Then copy your answer and paste your code below each number in this document.

Use the table above to answer the following by writing the SQL code. Do this code in sequential
order. Each number is related to the previous number.

1. Create the table above. Job_id is the primary key.

CREATE TABLE JOB(


JOB_ID VARCHAR2(10 BYTE) PRIMARY KEY,
JOB_TITLE VARCHAR2(35 BYTE) NOT NULL,
MIN_SALARY NUMBER(6),
MAX_SALARY NUMBER(6)
);

2. Add a new column on the table named job_category that accepts a string and it can
be null.

ALTER TABLE JOB


ADD JOB_CATEGORY VARCHAR2(4000);

3. Using the new table, insert a new row on the Jobs table. Use the following data: Job_id:
ST_Assist, Job_title: Stock Aid, Min_Salary: 5000, Max_salary: 13000, job_category:
M_Operator.

INSERT INTO JOB


(JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY,JOB_CATEGORY)
VALUES ('ST_Assist','Stock Aid',5000,13000,'M_Operator');

4. Show the all the jobid, job title, the sum of the minimum salaries of the employees and
the average of the minimum salaries of the employees that has an job title that ends
with “Representative”. Group it by their job_ids and job_titles. Show only the sum of
the

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
MIN_salaries that are less than 5000. Then arrange it by job_id. (Then draw the table of
the result)

SELECT JOB_ID,JOB_TITLE,
SUM(MIN_SALARY), AVG(MIN_SALARY)
FROM JOB WHERE JOB_TITLE LIKE '%Representative'
GROUP BY JOB_ID,JOB_TITLE HAVING SUM(MIN_SALARY) < 5000
ORDER BY JOB_ID;

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
Part 3:
Write a correct SQL statement for each problem and show the result of the statement. Use the tables below. You
may use SQL developer to help you with answering the questions. Copy and past the source code and the result
after each question.

Student
Student
Enrollment
StudentId StudName Age
A Mark 18 EnrollmentId EnrollmentDate StudentId SubjId
B Matthew 17 E100 Oct – 10 - 2015 A 1
C Ruth 20 E101 Oct – 11 - 2015 B 2
D John 15 E102 Nov – 10 - 2015 C 3
E103 Dec – 15 – 2015 D 1
E Sally 18
E104 Feb – 1 – 2015 E 3
F James 17 E105 Mar – 10 – 2015 F 2

Subject
SubjId SubjDescription Units Priceperunit
1 Math 3 400
2 Science 2 500
3 History 1 250

1.) Create an SQL statement that would show the minimum and maximum units of a subject. ( 5 points)
SELECT MIN(Units),MAX(Units) FROM Subject;

2.) Create an SQL statement that would show the student name, enrollment date and subject description of
the student who is enrolled in Math or Science. ( 5 points)
SELECT Student.StudName,Enrollment.EnrollmentDate,Subject.SubjDescri
ption
FROM Student
INNER JOIN Enrollment on Enrollment.Studentid = Student.Studentid
INNER JOIN Subject on Enrollment.Subjid = Subject.Subjid
WHERE Subject.SubjDescription = 'Math' OR Subject.SubjDescription =
'Science';

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
3.) Create a view, name it as EnrollDates, that would show all the enrollment dates of students who are
enrolled in the subject History. ( 5 points)
CREATE VIEW EnrollDates AS
SELECT Enrollment.EnrollmentDate, Subject.SubjDescription FROM Enrollme
nt
INNER JOIN Subject ON Subject.Subjid = Enrollment.Subjid
WHERE Subject.SubjDescription = 'History';

SELECT * FROM EnrollDates;

4.) Create a view name it as studentDetails, that would should show the student name, enrollment date the
total price per unit and subject description of students who are enrolled on the subject Science or History.(
5 points)
CREATE VIEW studentDetails AS
SELECT Student.StudName,Enrollment.EnrollmentDate,
(Subject.Priceperunit * Subject.Units) AS TotalPrice,Subject.SubjDes
cription
FROM Enrollment
INNER JOIN Student ON
Student.Studentid = Enrollment.Studentid
INNER JOIN Subject ON
Subject.Subjid = Enrollment.Subjid
WHERE Subject.SubjDescription = 'Science' OR Subject.SubjDescription
= 'History';

SELECT * FROM studentDetails;

5.) Create a view, name it as BiggestPrice, that will show the subject id and highest total price per unit of all
the subjects. The view should show only the highest total price per unit that are greater than 1000.

CREATE VIEW BiggestPrice AS


SELECT Subjid,(Priceperunit*Units)AS TOTALPRICE FROM Subject WHERE (Price
perunit*Units) > 1000;

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/
SELECT * FROM BiggestPrice

This study source was downloaded by 100000831283672 from CourseHero.com on 10-30-2022 21:08:53 GMT -05:00

https://www.coursehero.com/file/105259559/T2-TECHNICAL-VALDERAMA-SHANE-STEVENdocx/

You might also like