Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP WITH THIS QUERY IN NEEDS TO MATCH THE TABLE THAT BELOW. I will also the query I got but is incorrect. Write a

PLEASE HELP WITH THIS QUERY IN NEEDS TO MATCH THE TABLE THAT BELOW. I will also the query I got but is incorrect.
Write a query to display the managers SSN, managers first and last name with a space between them, department number, department name, employees SSN, employees first and last name with a space between them, and the following information about the employee's dependents: name, relationship and date of birth. The department number and name are that of the employee, not the manager. Name the columns as follows: Manager SSN, Manager Name, Department, Employee SSN, Employee Name, Dependent Name, Relationship and Dependent DOB. Sort the results by department number, employee SSN in all ascending order. See sample output below. (25 pts)
SELECT CONCAT(SUBSTRING(mgr.emp_ssn,1,3),'-', SUBSTRING(mgr.emp_ssn,4,2),'-', SUBSTRING(mgr.emp_ssn,6,4)) AS "Manager SSN",
CONCAT(mgr.emp_first_name, '', mgr.emp_last_name) AS "Manager Name",
CONCAT(e.emp_dpt_num, '', d.dpt_name) AS Department,
CONCAT(SUBSTRING(e.emp_ssn,1,3),'-', SUBSTRING(e.emp_ssn,4,2),'-', SUBSTRING(e.emp_ssn,6,4)) AS "Employee SSN",
CONCAT(e.emp_first_name, '', e.emp_last_name) AS "Employee Name",
dpt. dep_name AS "Dependent Name",
dpt. dep_relationship AS Relationship,
DATE_FORMAT(dpt.dep_date_of_birth, '%M %d,%Y') AS "Dependent DOB"
FROM employee e
JOIN department d ON e.emp_dpt_num = d.dpt_no
JOIN employee mgr ON d.dpt_mgrssn = mgr.emp_ssn
LEFT JOIN dependent dpt ON e.emp_ssn = dpt.dep_emp_ssn
ORDER BY e.emp_dpt_num ASC, e.emp_ssn ASC;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

show the relationship between kleene closuree and positive closure

Answered: 1 week ago