Question

In: Computer Science

SUBJECT: PROGRAMMING IN SQL 1. Create a view named vDepartmentInstructors that returns these columns: the DepartmentName...

SUBJECT: PROGRAMMING IN SQL

1. Create a view named vDepartmentInstructors that returns these columns:

  1. the DepartmentName column from the Departments table
  2. the LastName, FirstName, Status, and AnnualSalary columns from the Instructors table.

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:

  1. the FirstName and LastName from the Students table
  2. the CourseNumber, CourseDescription, and CourseUnits from the Courses table.

5. Write a SELECT statement that returns these columns from the vStudentCoursesMin view that you created in question 4:

  1. LastName, FirstName, CourseDescription.

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.

  1. This view should return some summary information about each student.
  2. Each row should include these columns: LastName, FirstName, CourseCount (the number of courses the student is taking), and UnitsTotal (the total units for the student).

7. Write a SELECT statement that uses the view that you created in question 6 to

  1. get the total units for the five students with the most units.

Return the LastName, FirstName and total units for each of those students.

Solutions

Expert Solution

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) ) ;


Related Solutions

In SQL we are working with functions 1. Write a SELECT statement that returns these columns...
In SQL we are working with functions 1. Write a SELECT statement that returns these columns from the Instructors table: a. The AnnualSalary column b. A column named MonthlySalary that is the result of dividing the AnnualSalary column by 12 c. A column named MonthlySalaryRounded that calculates the monthly salary and then uses the ROUND function to round the result to 2 decimal places 2. Write a SELECT statement that returns these columns from the Students table: a. The EnrollmentDate...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns 2.Alter the tables to add the columns 3.Alter the tables to create the primary and foreign keys
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns:...
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns: credits number (primary key) and degree name. 2. Write the statements to create a table named CANDIDATE with the following columns names. Pick the best column type: student_id, first name, last name, credits and graduation date. The credits column is a foreign key to the credits column in the REQUIREMENTS table. 3. Write the statement(s) to Insert 2 rows in your REQUIREMENTS table. Make...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
(SQL Coding) Create a view based on the Job History table. Name the view: view_job_history. Select...
(SQL Coding) Create a view based on the Job History table. Name the view: view_job_history. Select all columns to be included in the view. Add a WHERE clause to restrict the employee_id to be greater than 150. Add the WITH READ ONLY option. Show me the code used to create the view and the results of a select statement on the view.
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -  (10...
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -   1) The name of a medicine, sanitizer, or tip/trick for protecting yourself against transmission or fight the disease - STRING 2) The amount of money the item costs - NUMBER 3) The UPC code of the item - NUMBER 4) Manufacturing country of the item - STRING Connect to the SQL database with your HTML code, and make sure to show the results of...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
(SQL Coding) Create a read only view called view_emp_salary_rank_ro that selects the last name and salary...
(SQL Coding) Create a read only view called view_emp_salary_rank_ro that selects the last name and salary from the o_employees table and ranks the salaries from highest to lowest for the top three employees.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT