0% found this document useful (0 votes)
329 views10 pages

Technical Summative Assessment 2: Group 8

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

TECHNICAL

SUMMATIVE
ASSESSMENT 2

Group 8
John Paul Policarpio
Ameliah Talimongan
Kimberly Anne Dimal
CCS0021 LABORATORY
TECHNICAL ASSESSMENT 2

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.
DDL Code:

CREATE TABLE Tasks

(IdTask NUMERIC(11) not null PRIMARY KEY,

Name VARCHAR2(50),

Description VARCHAR2(250),

Work VARCHAR2(50),

IdProject NUMERIC(11) not null,

StartDate DATE,

EndDate DATE,

CreatedAt TIMESTAMP,

UpdatedAt TIMESTAMP,

Enabled VARCHAR(100));

CREATE TABLE Time_Category

(IdTimeCategory NUMERIC(11) not null PRIMARY KEY,

Name VARCHAR2(50),

Description VARCHAR2(250),

CreatedAt TIMESTAMP,

UpdatedAt TIMESTAMP,

Enabled VARCHAR(100));

CREATE TABLE User_data

(IdUser NUMERIC(11) not null PRIMARY KEY,

Name VARCHAR2(50),

LastName VARCHAR2(50),

Email VARCHAR2(50),

UserName VARCHAR2(50),

Password VARCHAR2(50),

CreatedAt TIMESTAMP,
UpdatedAt TIMESTAMP,

Enabled VARCHAR(100));

CREATE TABLE time_sheet

(IdTimeSheet NUMERIC(11) not null PRIMARY KEY,

Name VARCHAR2(50),

Description VARCHAR2(250),

IdProject NUMERIC(11) not null,

CreatedAt TIMESTAMP,

UpdatedAt TIMESTAMP,

Enabled VARCHAR(100),

IdUser NUMERIC(11) not null,

CONSTRAINT time_sheet_fk2 FOREIGN KEY (IdUser) references User_data (IdUser));

CREATE TABLE Time_Sheet_Hour

(IdTimeSheetHour NUMERIC(11) not null PRIMARY KEY,

IdTimeSheet NUMERIC(11) not null,

IdUser NUMERIC(11) not null,

IdTimeCategory NUMERIC(11) not null,

IdTask NUMERIC(11) not null,

Quantity NUMERIC(11),

Description VARCHAR2(250),

CONSTRAINT Time_Sheet_Hour_fk1 FOREIGN KEY (IdTimeSheet) references time_sheet(IdTimeSheet),

CONSTRAINT Time_Sheet_Hour_fk2 FOREIGN KEY (IdUser) references User_data(IdUser),

CONSTRAINT Time_Sheet_Hour_fk3 FOREIGN KEY (IdTimeCategory) references


Time_Category(IdTimeCategory),

CONSTRAINT Time_Sheet_Hour_fk4 FOREIGN KEY (IdTask) references Tasks(Id_Task));


Part 2:

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

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 JOBS

(JOB_ID VARCHAR2(10)NOT NULL,

JOB_TITLE VARCHAR(35)NOT NULL,

MIN_SALARY NUMBER(6,0),

MAX_SALARY NUMBER(6,0),

PRIMARY KEY(JOB_ID));
2. Add a new column on the table named job_category that accepts a string and it can be
null.

ALTER TABLE JOBS

ADD JOB_CATEGORY VARCHAR2(35);

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 jobs

(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, the sum of the salaries of the employees and the average of the
salaries of the employees that has an job id that ends with “ASST”. Group it by their
job_id. Show only the sum of the salary 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 jobs

WHERE job_title LIKE '%Representative'

GROUP BY job_id, job_title HAVING SUM(min_salary) < 5000

ORDER BY job_id;
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 paste the source code and the result
after each question.

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

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 MAX (Units) AS maxunits FROM subject;


SELECT MIN (Units) AS minunits 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 s.StudName, e.EnrollmentDate,sub.SubjDescription FROM student s

INNER JOIN enrollment e ON s.StudentId=e.Studentid

INNER JOIN subject sub ON e.Subjid=sub.Subjid

WHERE sub.Subjid IN (1,2);

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 e.EnrollmentDate FROM students s

INNER JOIN enrollment e ON s.Studentid = e.Studentid

INNER JOIN subject sub ON e.subjid=sub.subjid

WHERE sub.Subjid =3

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 s.StudName, e.EnrollmentDate,sub.Priceperunit*sub.Units AS


TotalPriceperunit,sub.SubjDescription
FROM students s

INNER JOIN enrollment e ON s.Studentid = e.Studentid

INNER JOIN subject sub ON e.SubjId = sub.Subjid

WHERE sub.Subjid IN (2,3)

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 sub.Subjid,sub.Priceperunit*sub.Units AS TotalPrice

FROM subject sub WHERE sub.Priceperunit*sub.Units>1000

You might also like