Lecture 4 - Having Flashcards
1
Q
What is having?
A
condition to select/reject a group after grouping!
2
Q
EXAMPLE OF HAVING :
Show the number of employees per project only from those projects
with more than 2 employees. Include the project name in the results.
A
SELECT P.PNAME, COUNT ()
FROM PROJECT AS P, WORKS_ON AS W
WHERE P.PNUMBER = W.PNO
GROUP BY P.PNAME
HAVING COUNT() > 2
3
Q
What is wrong with this query?
SELECT DNO, COUNT ()
FROM EMPLOYEE
WHERE Salary > 40000
GROUP BY DNO
HAVING COUNT () > 5;
A
We are filtering out employees with small salary before grouping, we still need to include them in the count however.
4
Q
Can sets in sql be named?
A
Yes and hence used as a variable