Lecture 4 - Having Flashcards

1
Q

What is having?

A

condition to select/reject a group after grouping!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can sets in sql be named?

A

Yes and hence used as a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly