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.
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...
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...
Write a SQL statement which joins the parts table with the supplier table and lists the...
Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query. Write a SQL statement which joins the parts table with the suppliers table and lists...
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
Write an SQL statement to show which customers boughtwhich items, and include any items that...
Write an SQL statement to show which customers bought which items, and include any items that have not been sold. Include LastName, FirstName, InvoiceNumber, InvoiceDate,ItemNumber, ItemDescription, ArtistLastName, and ArtistFirstName. Use a join using JOIN ON syntax, and sort the results by ArtistLastName and ArtistFirstName in ascending order (Hint: you have to use a RIGHT JOIN on the last step).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT