Question
You are not allowed to use more than 2 SELECT or use any of these SQL keywords: WITH, EXISTS, COUNT, ORDER BY, ASC, DESC, LIMIT,
You are not allowed to use more than 2 SELECT or use any of these SQL keywords: WITH, EXISTS, COUNT, ORDER BY, ASC, DESC, LIMIT, TOP, NATURAL JOIN, JOIN, ON, SOME, ANY, ALL, row_number, dense_rank. Otherwise, no marks will be given
You are given the following view table which is derived from a university staff table. [12 marks]
CREATE VIEW StaffDeptAge AS SELECT sid, dept, age FROM STAFF;
sid the staff id
dept the code (e.g., CS, EE) of the department that the staff works in
age the age of the staff member
Write only ONE SQL statement to answer the following. For each department, display the department code, and a pair of staff ids (sid). The first (second) sid is the member of staff who is oldest (youngest) among all the members of staff in that department. You can assume that there is only one oldest and one youngest member of staff per department. Your SQL should produce a result table that looks like the one below where sid1 (sid2) is the ids of the first (second) staff id:
example:
dept | sid1 | sid2 |
CC | s123 | s231 |
EE | s421 | s152 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started