ANS2
ANS2
ANS2
1)
sql
SELECT STUDENT_NAME
FROM STUDENT
WHERE GENDER = 'male' AND BIRTHDATE > '2000-10-01';
(2)
sql
SELECT STUDENT_NAME
FROM STUDENT
WHERE LENGTH(ADDRESS) >= 8
ORDER BY STUDENT_NAME ASC;
(3)
sql
SELECT COURSE_TITLE
FROM COURSE
WHERE STAFF_ID IN ('BEAN', 'SAM');
(4)
vbnet
(5)
sql
SELECT S1.STAFF_NAME
FROM STAFF S1, STAFF S2
WHERE S1.BOSS_ID = S2.STAFF_ID
AND S1.SALARY > S2.SALARY;
(6)
sql
SELECT STAFF_NAME
FROM STAFF
WHERE SALARY < (SELECT AVG(SALARY) FROM STAFF);
(7)
Sql
SELECT COURSE_TITLE
FROM COURSE
WHERE COURSE_ID NOT IN (SELECT COURSE_ID FROM TAKEN);
(8)
sql
SELECT S1.STAFF_NAME
FROM STAFF S1, STAFF S2
WHERE S1.STAFF_ID = S2.BOSS_ID
AND S2.DEPARTMENT = 'Engineering'
AND S1.GENDER = 'male';
(9)
Sql
QB
Explanation:
(1) To retrieve the birthdays of managers:
SELECT Bdate FROM EMPLOYEE WHERE Ssn IN (SELECT Mgr_ssn FROM DEPARTMENT)
This query will select the birthdate ('Bdate') from the 'EMPLOYEE' table where the 'Ssn' matches
any 'Mgr_ssn' from the 'DEPARTMENT' table.
To retrieve the birthdays of managers, we need to join the EMPLOYEE and
DEPARTMENT tables on the Mgr_ssn and Ssn attributes respectively. Then,we can filter the result
to only show the birthdays of the managers.
Query:
1 SELECT E.Bdate
2 FROM EMPLOYEE E, DEPARTMENT D
3 WHERE E.Ssn=D.Mgr_ssn;
4
Output:
1 1962-09-15
2 1955-12-08
3 1969-03-29
4
Therefore,the birthdays of managers are September 15,1962;December 8,1955;and March
29,1969.
Note:The output may differ depending on the date format of the DBMS.
(2) To retrieve the salaries of all male employees working in the department No.5: SELECT 'Salary'
FROM 'EMPLOYEE' WHERE 'Sex' = 'M' AND 'Dno'='5'
This query will select the 'Salary' from the 'EMPLOYEE' table where Sex is 'M' and Dno is 5.
Note: This assumes that the 'Dno' column in the 'EMPLOYEE' table corresponds to the 'Dnumber'
column in the 'DEPARTMENT' table.
Explanation:
(3) To list the last names of employees in the Research department whose salary is above 35000:
SELECT Lname FROM EMPLOYEE WHERE Dno =5 AND Salary>35000
This query will select the 'Lname' from the 'EMPLOYEE' table where 'Dno' is '5' and 'Salary' is
greater than '35000'.
(4) To retrieve the last names and Ssns of employees who work on all projects:
SELECT Lname
FROM EMPLOYEE
WHERE Sex = 'M'
AND Super_ssn <> (
SELECT Ssn
FROM EMPLOYEE
WHERE Lname = 'Wong'
AND Fname = 'Franklin'
)
This query will select the 'Lname' from the 'EMPLOYEE' table where 'Sex' is 'M' and 'Super_ssn'
does not match the 'Ssn' of an employee whose 'Lname' is 'Wong' and whose 'Fname' is
'Franklin'.
(6) To list the first names of all employees who work on the project 'Productx' and have a
daughter as the dependent:
SELECT Fname
FROM EMPLOYEE
WHERE Essn IN (
SELECT Essn
FROM DEPENDENT
WHERE Sex = 'F'
AND Relationship = 'Daughter'
AND Esse IN (
SELECT Essn
FROM WORKS_ON
WHERE Pno IN (
SELECT Pnumber
FROM PROJECT
WHERE Pname = 'ProductX'
)
)
)
This query will select the 'Fname' from the 'EMPLOYEE' table where the 'Essn'
matches an Esse in the DEPENDENT table where the Sex is 'F', the 'Relationship' is 'Daughter', and
the 'Esse' matches an 'Essn' in the 'WORKS_ON' table where the 'Pno' matches a 'Pnumber' in the
'PROJECT' table where the 'Pname' is 'ProductX'.
(7)The last name of each department manager who has at least one daughter as a dependent:
Lname
Wallace
Lname
Zelaya
Narayan
English
Jabbar
Borg
Fname
Franco
Alicia
Ranesh
Joyce
Ahmad
James
(9) The last names and Ssns of employees who work on at least one project in Houston and
whose department is located in Sugarland or Bellaire:
Ssn
453453453
123456789
987654321