Professional Documents
Culture Documents
EMPLOYEE
FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN
DEPARTMENT
DNAME DNUMBER MGRSSN MGRSTARTDATE
DEPT_LOCATIONS
DNUMBER
DLOCATION
PROJECT
PNAME
WORKS_ON
ESSN
PNO
HOURS
DEPENDENT
ESSN
DEPENDENT_NAME
SEX
BDATE
RELATIONSHIP
DNO
Examples
Retrieve the birthdate and address of the employee whose name is John
B. Smith.
SELECT
FROM
WHERE
BDATE, ADDRESS
EMPLOYEE
FNAME=John AND MINIT=B AND LNAME=Smith
Retrieve the name and address of all employees who work for the
Research department.
SELECT
FROM
WHERE
For every project located in Stafford, list the project number, the
For each employee, retrieve the employees first and last name and the
FROM
EMPLOYEE E, EMPLOYEE S
WHERE
E.SUPERSSN=S.SSN
SSN
FROM
EMPLOYEE
SELECT
SSN, DNAME
FROM
EMPLOYEE, DEPARTMENT
SELECT
FROM
Make a list of all project numbers for projects that involve an employee whose last
Find the names of employees whose salary is greater than the salary of
LNAME, FNAME
EMPLOYEE
SALARY > ALL (SELECT SALARY FROM EMPLOYEE
WHERE DNO=5)
Retrieve the name of each employee who has a dependent with the
E.FNAME, E.LNAME
EMPLOYEE E
E.SSN IN (SELECT ESSN
FROM DEPENDENT
WHERE ESSN=E.SSN AND
E.FNAME=DEPENDENT_NAME AND
SEX=E.SEX)
Retrieve the name of each employee who works on all the projects
EMPLOYEE
WHERE
FROM DEPENDENT
WHERE SSN=ESSN)
EMPLOYEE
WHERE
EXISTS (SELECT *
FROM DEPENDENT
WHERE SSN=ESSN)
AND
EXISTS (SELECT *
FROM DEPARTMENT
WHERE SSN=MGRSSN)
Retrieve the social security numbers of all employees who work on project
number 1, 2, or 3.
SELECT
DISTINCT ESSN
FROM
WORKS_ON
WHERE
PNO IN (1,2,3)
SELECT
FNAME, LNAME
FROM
EMPLOYEE
WHERE
SUPERSSN IS NULL
Find the sum of the salaries of all employees, the maximum salary, the
FROM
EMPLOYEE
Find the sum of the salaries of all employees of the Research department,
as well as the maximum salary, the minimum salary, and the average salary
in this department.
SELECT SUM(SALARY), MAX(SALARY), MIN(SALARY),
AVG(SALARY)
FROM
EMPLOYEE, DEPARTMENT
WHERE
DNO=DNUMBER AND DNAME=Research
Retrieve the total number of employees in the company and the number of
COUNT(*)
EMPLOYEE
COUNT(*)
EMPLOYEE, DEPARTMENT
DNO=DNUMBER AND DNAME=Research
EMPLOYEE
For each project, retrieve the project number, the project name, and the
For each project on which more than two employees work, retrieve the
project number, the project name, and the number of employees who
work on the project.
SELECT PNUMBER, PNAME, COUNT(*)
FROM
PROJECT, WORKS_ON
WHERE
PNUMBER=PNO
GROUP BY PNUMBER, PNAME
HAVING
COUNT(*) > 2
10
For each project, retrieve the project number, the project name, and the
For each department having more than five employees, retrieve the
DNAME, COUNT(*)
DEPARTMENT, EMPLOYEE
DNUMBER=DNO AND SALARY>40000 AND
DNO IN
(SELECT DNO
FROM
EMPLOYEE
GROUP BY DNO
HAVING COUNT(*) > 5)
GROUP BY DNAME
11
FROM
WHERE
Retrieve a list of employees and the projects they are working on, ordered
FROM
WHERE
12