Lecture 4 - Groupings Flashcards

1
Q

The process of grouping is?

A

Partition a relation into groups based on grouping attribute, i.e.,
clustering tuples having the same value in the grouping attribute.

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

What is the statement that can be used for grouping?

A

GROUP BY

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

Example of grouping by departement and working out the average salary?

A

SELECT DNO, COUNT (*), AVG (Salary)
FROM EMPLOYEE
GROUP BY DNO;

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

The grouping attribute must appear…

A

in SELECT

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

What happens if a grouping attribute has NULL values?

A

There is a seperate group created for NULLS.

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

Is grouping computationally heavy?

A

yes

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

What should we avoid doing?

A

Grouping by PK as this doesn’t do anything

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

EXAMPLE : How many employees are working in each project? Include the
project name at the results

A

SELECT P.PNAME, COUNT (*) //employees per project
FROM PROJECT AS P, WORKS_ON AS W
WHERE P.PNUMBER = W.PNO
GROUP BY P.PNAME;

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

Is it possible to group by more than 1 attribute ?

A

YEs

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

Example of multi-attribute grouping?

A

SELECT COUNT(*), E.DNO, E.SALARY
FROM EMPLOYEE AS E
GROUP BY E.DNO, E.SALARY
ORDER BY E.DNO

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