Question

In: Computer Science

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 column

b. A column that returns the four-digit year that’s stored in the EnrollmentDate column

c. A column that returns only the day of the month that’s stored in the EnrollmentDate column

d. A column that returns the result from adding four years to the EnrollmentDate column; use the CAST function so only the year is returned

3. Write a SELECT statement that returns these columns:

a. The DepartmentName column from the Departments table

b. The CourseNumber column from the Courses table

c. The FirstName column from the Instructors table

d. The LastName column from the Instructors table

Add a column that includes the first three characters from the DepartmentName column in uppercase, concatenated with the CourseNumber column, the first character of the FirstName column if this column isn’t null or an empty string otherwise, and the LastName column. For this to work, you will need to cast the CourseNumber column to a character column.

4. Write a SELECT statement that returns these columns from the Students table:

a. The FirstName column

b. The LastName column

c. The EnrollmentDate column

d. The GraduationDate column

e. A column that shows the number of months between the EnrollmentDate and GraduationDate columns

Return one row for each student who has graduated.

5. Write a CTE with a SELECT statement that returns one row for each student that has courses with these columns:

a. The StudentID column from the Students table

b. The sum of the course units in the Courses table

6. Write a SELECT statement that uses this CTE to return these columns for each student:

a.The StudentID column from the CTE

b.The sum of course units from the CTE

An indication of whether the student is fulltime or parttime (Hint: To determine whether a student is fulltime, use the IIF function to test if the sum of course units is greater than 9.) The total tuition (Hint: To calculate the tuition, use the IIF function to determine whether a student is fulltime or partime. Then, multiply the sum of course units by the PerUnitCost column in the Tuition table and add that to either the FullTimeCost or PartTimeCost column in the Tuition table. To do that, use a cross join to join the CTE and the Tution tables. This makes the columns from the Tuition table available to the SELECT statement.)

Solutions

Expert Solution

(1) SELECT AnnualSalary ,((Annual_Salary / 12) AS MonthlySalary, ROUND(Annual_Salary / 12.0, 2) AS 'MonthlySalaryRounded '
FROM Instructors ;
(2)

SELECT EnrollmentDate,YEAR(EnrollmentDate) AS OrderYear,

DAY(EnrollmentDate) AS EnrollmentDate,DATEADD(YEAR,4,EnrollmentDate) AS '4yearEnrollmentDate'

FROM Students ;

(3)

SELECT Departments.DepartmentName , Courses.CourseNumber , Instructors.FirstName,

Instructors.LastName

FROM Departments , Courses , Instructors

(4)

SELECT FirstName ,LastName ,EnrollmentDate,GraduationDate ,

(((Date.Year([GraduationDate ])-Date.Year([EnrollmentDate ]))*12) + Date.Month([GraduationDate ]) - Date.Month([EnrollmentDate ]) ) AS NumberofMonths

FROM Students ;

(5) WITH UnitsSummary AS (
SELECT Students.StudentID,SUM(CourseUnits) AS TotalUnits
FROM Students JOIN StudentCourses ON Students.StudentID = StudentCourses.StudentID
JOIN Courses ON StudentCourses.CourseID = Courses.CourseID
GROUP BY Students.StudentID,CourseUnits
)
(6) SELECT StudentID, TotalUnits, IIF(TotalUnits > 9,'FUlltime','Parttime'),
FullTimeCost + (TotalUnits * PerUnitCost) AS Tuition
FROM UnitsSummary
CROSS JOIN Tuition

Related Solutions

Write a SELECT statement that returns these columns using a JOIN of three tables: order_date from...
Write a SELECT statement that returns these columns using a JOIN of three tables: order_date from the orders table shipped_date from the orders table order_qty from the order_details table title from the items table artist from the items table unit_price from the items table Result table should be in order of order_date in ascending order
Can you please implement this in Oracle sql Write a SELECT statement that returns one row...
Can you please implement this in Oracle sql Write a SELECT statement that returns one row for each customer that has orders with these columns: The email_address from the Customers table A count of the number of orders The total amount for each order (Hint: First, subtract the discount amount from the price. Then, multiply by the quantity.) Return only those rows where the customer has more than 1 order. Sort the result set in descending sequence by the sum...
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: the DepartmentName column from the Departments table 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...
Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What...
Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What is the total amount ordered for each product? Return these columns: The product name from the Products table The total amount for each product in the Order_Items (Hint: You can calculate the total amount by subtracting the discount amount from the item price and then multiplying it by the quantity) Use the ROLLUP operator to include a row that gives the grand total.
HOW TO: 1. Write the SQL statement to show workers with names that have the letter...
HOW TO: 1. Write the SQL statement to show workers with names that have the letter ? before the last character. 2. Write the SQL statement to show all staff where the 2nd letter of their last names is ′?′ 3. Write the SQL statement to show all staff where the 1stletter of their first names is ′?′ and 3rd letter ′ℎ' DROP TABLE IF EXISTS staff; CREATE TABLE staff ( staffNo VARCHAR(4) UNIQUE, fName VARCHAR(16), lName VARCHAR(16), position VARCHAR(16),...
1. Write a SQL statement which joins the rider_student table with the rider_major table and lists...
1. Write a SQL statement which joins the rider_student table with the rider_major table and lists the rider student name and the name of the major (major_name) and the description of the major for which they are currently assigned. (You may use the SQL 'join' subclause, or simply express the join as part of the 'where' clause by indicating that you only want records where the primary key of the child table, rider_major, equals the corresponding foreign key of the...
1Write an SQL statement utilizing the WHERE, LIKE, and HAVING clauses that select gender, and the...
1Write an SQL statement utilizing the WHERE, LIKE, and HAVING clauses that select gender, and the email addresses that belong to female users and have an email address that contains a number (0 to 9) within it. Create an alias for the resultant email column name and name it ‘Email Addresses Female With Numbers’ IPV4 (Internet Protocol Version 4) addresses utilize a notation known as the dotted-quad notation. Quad because an IPV4 address is actually a series of 4 numbers...
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade...
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade based on the value stored in a variable called grade. Use the ACC      grading system described in the course syllabus to create the block and set     the initial value of grade as 95. Use only one print statement and no      logical operators in your code. Assume a grade can exceed 100, but it      can’t be negative. Grade Scale: Grade Scale:...
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create...
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create a login for AdventureWorks employees. An employee login should be composed of the first letter of a person's first name combined with their last name. In addition, the login should be all lower case characters. All the required information is located in Person.Person table. Employees can be identified by "EM" value in the PersonType field. The output should include BusinessEntityID, first name (FirstName), last...
Consider the following SQL script. QUESTION: Which best completes the following statement(Select 3): Table SELECT TABLE...
Consider the following SQL script. QUESTION: Which best completes the following statement(Select 3): Table SELECT TABLE NAME is in SELECT NORMAL FORM and is SELECT FORM TYPE ***Note: The answer choices are at the bottom Assume also that even if there are some issues you cannot resolve them. Report on the current state of the database based on the code that you have been provided. CREATE TABLE ASSIGNMENT ( ASSIGN_NUM int, ASSIGN_DATE datetime, PROJ_NUM varchar(3), EMP_NUM varchar(3), ASSIGN_HOURS float(8), ASSIGN_CHG_HOUR...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT