Chapter 07
Chapter 07
Navathe
CHAPTER 7
This query will select the Essns of all employees who work the same
(project, hours) combination on some project that employee ‘John
Smith’ (whose Ssn = ‘123456789’) works on.
AND
EXISTS (SELECT *
FROM Department
WHERE Ssn= Mgr_Ssn) ;
n If no matching tuple
n If no matching tuple
ALTERNATE SYNTAX:
SELECT E.Lname , S.Lname
FROM EMPLOYEE E, EMPLOYEE S
WHERE E.Super_ssn + = S.Ssn
Q19: SELECT
SUM (Salary), MAX (Salary), MIN (Salary), AVG
(Salary)
FROM EMPLOYEE;
n The result can be presented with new names:
Q19A: SELECT
SUM (Salary) AS Total_Sal, MAX (Salary) AS
Highest_Sal, MIN (Salary) AS Lowest_Sal, AVG
(Salary) AS Average_Sal
FROM EMPLOYEE;
n INCORRECT QUERY:
SELECT Dno, COUNT (*)
FROM EMPLOYEE
WHERE Salary>40000
GROUP BY Dno
HAVING COUNT (*) > 5;
SELECT *
FROM SUP_EMP;
n The above query starts with an empty SUP_EMP and
successively builds SUP_EMP table by computing
immediate supervisees first, then second level
supervisees, etc. until a fixed point is reached and no
more supervisees can be added
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 7- 49
EXPANDED Block Structure of SQL
Queries
R5:
CREATE TRIGGER SALARY_VIOLATION
BEFORE INSERT OR UPDATE OF Salary, Supervisor_ssn ON
EMPLOYEE
permanently
n Modify view query into a query on underlying base