Uploaded by nanadarkwa16

8545021 CSM297

advertisement
Name: Darkwa Nana Antwi Awuah
Index Number: 8545021
1. Assuming the retirement age is 60, list the names of employees who have retired or are due for
retirement
Query
SELECT Fname, Minit, Lname
FROM employee
WHERE DATEADD(year, 60, Bdate) <= GETDATE()
2. List all employees who will be going on retirement in 2025
Query
SELECT Fname, Minit, Lname, Bdate, DATEADD(year, 60, Bdate) AS retirement_date
FROM employee
WHERE DATEADD(year, 60, Bdate) BETWEEN '2025-01-01' AND '2025-12-31'
3. Determine how many employees are older than their supervisor
Query:
SELECT COUNT(*) AS num_older
FROM employee e1
JOIN employee e2 ON e1.Super_ssn = e2.Ssn
WHERE e1.Bdate < e2.Bdate
4. List the age diff between all employees and their supervisor
Query:
SELECT e.Fname, e.Minit, e.Lname, DATEDIFF(year, e.Bdate, e2.Bdate) AS age_diff
FROM employee e
JOIN employee e2 ON e.Super_ssn = e2.Ssn
5. List the manes of all supervisors and their ages
Query:
SELECT e2.Fname, e2.Minit, e2.Lname, DATEDIFF(year, e2.Bdate, GETDATE()) AS age
FROM employee e
JOIN employee e2 ON e.Super_ssn = e2.Ssn
GROUP BY e2.Fname, e2.Minit, e2.Lname, e2.Bdate
Download