In: Computer Science
SUBJECT: PROGRAMMING IN SQL
1. Create a view named vDepartmentInstructors that returns these columns:
2. Write a SELECT statement that returns all the columns from the vDepartmentInstructors view that you created in question 1.
Return one row for each fulltime instructor in the English department.
3. Write an UPDATE statement that updates the vDepartmentInstructors view you created in question 1 so it increases the annual salary for each fulltime instructor in the English department by 10%. Then, run the SELECT statement you wrote in question 2 to be sure this worked correctly.
4. Create a view named vStudentCoursesMin that returns these columns:
5. Write a SELECT statement that returns these columns from the vStudentCoursesMin view that you created in question 4:
Return one row for each course with three units.
Sort the results by LastName and then by FirstName.
6. Create a view named vStudentCoursesSummary that uses the view you created in question 4.
7. Write a SELECT statement that uses the view that you created in question 6 to
Return the LastName, FirstName and total units for each of those students.
Answer.1.
CREATE VIEW vDepartmentInstructors
AS
SELECT Departments.DepartmentName,
Instructors.FirstName, Instructors.LastName,
Instructors.Status,
Instructors.AnnualSalary FROM Departments,
Instructors ;
Answer.2.
SELECT *FROM vDepartmentInstructors ;
SELECT *FROM vDepartmentInstructors where DepartmentName='English' ;
Answer.3.
UPDATE vDepartmentInstructors
SET
AnnualSalary=AnnualSalary+(AnnualSalary*10/100)
WHERE DepartmentName='English' ;
running SELECT statement here--
SELECT *FROM vDepartmentInstructors ;
Answer.4.
CREATE VIEW vStudentCoursesMin
AS
SELECT Students.FirstName, Students.LastName,
Courses.CourseNumber, Courses.CourseDescription,
Courses.CourseUnits FROM Students, Courses ;
Answer.5.
SELECT LastName, FirstName, CourseDiscription FROM vStudentCoursesMin ;
SELECT *FROM vStudentCoursesMin WHERE CourseUnits=3 ; // result having three CourseUnit
SELECT *FROM vStudentCoursesMin ORDER BY LastName ; // sorting result by Lastname
SELECT *FROM vStudentCoursesMin ORDER BY FirstName ; // sorting result by FirstName
Answer.6.
CREATE VIEW vStudentCoursesSummary
AS
SELECT FirstName, LastName,
COUNT(DISTINCT CourseName) as CourseCount,
SUM(CourseUnits) as UnitsTotal
FROM vStudentCoursesMin ;
Answer.7.
SELECT LastName, FirstName, UnitsTotal
FROM vStudentCoursesSummary
WHERE (UnitsTotal IN (SELECT
TOP(5) UnitsTotal FROM
vStudentCoursesSummary as table1 GROUP BY
UnitsTotal ORDER BY UnitsTotal DESC) ) ;