T2-TECHNICAL Rivera

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

CCS0021 LABORATORY

TECHNICAL ASSESSMENT 2
Name Rollen A. Rivera.

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.
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.

Job_Temp

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.

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

3. Using the new table, insert a new row on the Job_Temp table. Use the following data:
Job_id: ST_Assist, Job_title: Stock Aid, Min_Salary: 5000, Max_salary: 13000,
job_category: 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 show the table of the result when the SQL code is RUN)
• Part 2:

• drop table Job;

• Create table Job(Job_ID varchar2(10),Job_Title varchar2(35),Min_salary


number(6,0),max_salary number(6,0));
desc job;
insert into Job values(101,'Phone Representative',5000,10000);
insert into Job values(102,'System Analysis',5000,12000);
Select * from Job;

• /* 1*/

• alter table Job add Primary key(Job_ID);

• desc Job;


• /* 2 */

• alter table Job add(job_Category varchar2(30));


desc job;
Select * From Job;

• /* 3 */
insert into Job values('ST_Assist','Stock Aid',5000,13000,'M_Operator');
Select * from Job;

• /* 4 */

• Select job_ID,Job_Title,sum(Min_salary),Avg(Min_salary) from Job where


Job_Title like '%Representative' group by job_ID,Job_Title 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 past the source code and the result
after each question.

Student
Student
Enrollment
StudentId StudName Age
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
E103 Dec – 15 – 2015 D 1
D John 15
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)

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)

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)

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)

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. (5
points)

/*Table Drop*/
drop table Student;
drop table Enrollment;
drop table Subject;

/* Create new table*/

Create table Student(StudentID varchar2(2),StudName varchar2(30),Age int);


desc Student;
insert into Student values('A','Mark',18);
insert into Student values('B','Mathew',17);
insert into Student values('C','Ruth',20);
insert into Student values('D','John',15);
insert into Student values('E','Sally',18);
insert into Student values('F','James',17);
Select * From Student;

Create table Subject(Subjid int Primary key,SubjDescription varchar2(25),Units


int,Priceperunit int);
insert into Subject values(1,'Math',3,400);
insert into Subject values(2,'Science',2,500);
insert into Subject values(3,'History',1,250);
Select * from Subject;
Create table Enrollment(EnrollmentID varchar2(5),EnrollmentDate date,StudentID
varchar2(20),Subjid int);
desc Enrollment;
insert into Enrollment values('E100','10-OCT-2015','A',1);
insert into Enrollment values('E101','11-OCT-2015','B',2);
insert into Enrollment values('E102','10-NOV-2015','C',3);
insert into Enrollment values('E103','15-DEC-2015','D',1);
insert into Enrollment values('E104','01-FEB-2015','E',3);
insert into Enrollment values('E105','10-MAR-2015','F',1);
Select * from Enrollment;

/*Query */

/*Query */
/* 1 */
Select min(Units),max(Units)from Subject;
/* 2 */

Select Student.StudName,Enrollment.EnrollmentDate,Subject.SubjDescription from


Student inner join Enrollment on Student.StudentID=Enrollment.StudentID inner join
Subject on Subject.Subjid=Enrollment.Subjid where Subject.SubjDescription
in('Math','Science');

/*3 */
drop view EnrollmentDates;
Create View EnrollmentDates as Select Enrollment.EnrollmentDate from Enrollment
inner join Subject on Subject.Subjid=Enrollment.Subjid where Subject.SubjDescription
in('History');
Select * from EnrollmentDates;

/* 4 */

drop view StudentDetails1;


Create View StudentDetails1 as Select
Student.StudName,Enrollment.EnrollmentDate,Subject.SubjDescription,Priceperunit
from Student inner join Enrollment on Student.StudentID=Enrollment.StudentID inner
join Subject on Subject.Subjid=Enrollment.Subjid where Subject.SubjDescription
in('History','Science');
Select * from StudentDetails1;
/* 5 */
drop view BiggestPrice;
Create View BiggestPrice as Select Subjid,Priceperunit from Subject where Priceperunit
=(Select max(Priceperunit) from Subject);
Select * from BiggestPrice;

You might also like