# 9.7. Exercises for Unary Operators¶

Here are some exercises to ensure mastery of what you have read so far. For each one, first try to write down in the short answer box the name of each result relation. Then use the show button to reveal what we called them. If we don’t match, consider whether your version is reasonable or whether the one given is more precise. After that, you can practice determining the identifier and the base of each result relation.

Try as few or as many as you wish for practice, but be sure to try at least one from each operator.

## 9.7.1. Filter¶

What would be the result relation name of each of the following charts?

Click show to see the answer and then practice knowing what the identifier of the result is.

The following image of 4 precedence charts using Filter will be repeated again below.

Q-1: Write the result relation name for A, B, C, and D

Now check yours with our versions by showing them. Note that there are multiple ways to be precise or accurate, so your answers may be just fine even if they are not just like those you see revealed. Notice haw we even showed different ways of describing equality in A versus C and D. Also, I personally prefer the use of ‘whose’ in A and B revealed below; what about you?

Here are the above 4 charts again:

Now practice knowing the base noun and the identifying attributes that are indicative of that base. Show each question to try the exercise for each result relation. (This is so you can hide and effectively collapse them out of the way.)

Result relation A:

Result relation B:

Result relation C:

Result relation D:

Note

The key idea you should be owning after these exercises is that the base of the result relation after a Filter does not change, and thus neither does its identifier, made up of the input relation’s identifying attributes(s).

## 9.7.2. Project¶

What would be the result relation name of each of the following charts?

Q-6: Write the result relation name for A, B, C, and D

Now check yours with our versions by showing them. Note that there is one straightforward pattern for a precise name for the result with Project, so your answers should be just like ours.

Here are the above 4 charts again:

Now practice knowing the base noun and the identifying attributes that are indicative of that base. Show each one to try it.

Result relation A:

Result relation B:

Result relation C:

Result relation D:

Note

The key idea you should be owning after these exercises is that the base of the result relation after a Project does not change, and thus neither does its identifier, made up of the input relation’s identifying attributes(s).

## 9.7.3. Reduce¶

Next, let us practice some naming of result relations for reduce.

Tip

Because with Reduce we will now be declaring new identifying columns, we must remember this: No columns in an identifier of a result relation can be null. Note below what the achievement data, which will be used in some of the following examples, contains:

Achievement

achId

creatureId

skillCode

proficiency

achDate

test_townId

1

1

A

3

2020-07-24 21:37:53

a

2

1

E

3

2017-09-15 15:35:00

d

3

1

A

3

2018-07-14 14:00:00

a

4

1

E

3

2020-07-24 21:37:53

d

5

5

Z

6

2016-04-12 15:42:30

t

6

3

Z

4

2018-07-15 00:00:00

be

7

3

Z

4

2018-07-15 00:00:00

be

8

3

Z

4

2018-07-15 00:00:00

be

9

4

Z

3

2018-06-10 00:00:00

a

10

11

PK

10

1998-08-15 00:00:00

le

11

12

PK

10

2016-05-24 00:00:00

le

12

13

PK

10

2012-08-06 00:00:00

le

13

8

PK

1

NULL

t

14

9

THR

10

2018-08-12 14:30:00

mv

15

10

THR

10

2018-08-12 14:30:00

mv

16

7

B2

19

2017-01-10 16:30:00

d

17

9

B2

19

2017-01-10 16:30:00

d

18

4

TR4

85

2012-07-30 00:00:00

le

19

5

TR4

85

2012-07-30 00:00:00

le

20

2

TR4

85

2012-07-30 00:00:00

le

21

1

TR4

85

2012-07-30 00:00:00

le

22

9

D3

8

2020-07-24 16:37:53

sw

23

13

D3

8

2020-07-24 16:37:53

sw

24

7

D3

8

2020-07-24 16:37:53

sw

Q-11: Why is the shape of the result labeled A different than the others? How might your try to name it?

Click Show to compare your answer to our reason.

Q-12: What are the names of result relations B, C, and D?

Click show to see what we suggest.

Here are the above 4 charts again:

Now practice knowing the base noun and the identifying attributes that are indicative of that base. Show each one to try it.

Result relation B:

Result relation C:

Result relation D:

Note

The concepts to master by doing these exercises are that the base of the result relation always changes from that of the input relation when doing a Reduce operation and there are cases we can try that result in a Bad Reduce if we are not careful about the columns we choose to identify the result relation.

## 9.7.4. Group¶

With the following Group exercises, we have several cases, so we will display them one at a time, rather than together as we did for the previous examples.

Case 1:

Q-16: The result relation name A is:

Case 2:

Q-18: The result relation name B is:

Case 3:

Q-20: The result relation name C is:

Case 4:

Q-22: The result relation name D is:

Case 5: Let’s try something just a bit different.

Case 6:

Case 7:

Q-28: The name I is:

Choose Show to reveal a possible way to name the above result.

Case 8:

Tip

Remember: No columns in an identifier of a result relation can be null. Note above when you show the answer, the middle data values tab can remind you what the achievement data contains.

Q-30: The result relation name J is:

For this interesting query, it would be good for you to practice the SQL version. Change the basic SQL query below to match this precedence chart.

Achievement

achId

creatureId

skillCode

proficiency

achDate

test_townId

1

1

A

3

2020-07-24 21:37:53

a

2

1

E

3

2017-09-15 15:35:00

d

3

1

A

3

2018-07-14 14:00:00

a

4

1

E

3

2020-07-24 21:37:53

d

5

5

Z

6

2016-04-12 15:42:30

t

6

3

Z

4

2018-07-15 00:00:00

be

7

3

Z

4

2018-07-15 00:00:00

be

8

3

Z

4

2018-07-15 00:00:00

be

9

4

Z

3

2018-06-10 00:00:00

a

10

11

PK

10

1998-08-15 00:00:00

le

11

12

PK

10

2016-05-24 00:00:00

le

12

13

PK

10

2012-08-06 00:00:00

le

13

8

PK

1

NULL

t

14

9

THR

10

2018-08-12 14:30:00

mv

15

10

THR

10

2018-08-12 14:30:00

mv

16

7

B2

19

2017-01-10 16:30:00

d

17

9

B2

19

2017-01-10 16:30:00

d

18

4

TR4

85

2012-07-30 00:00:00

le

19

5

TR4

85

2012-07-30 00:00:00

le

20

2

TR4

85

2012-07-30 00:00:00

le

21

1

TR4

85

2012-07-30 00:00:00

le

22

9

D3

8

2020-07-24 16:37:53

sw

23

13

D3

8

2020-07-24 16:37:53

sw

24

7

D3

8

2020-07-24 16:37:53

sw

Note

The concepts to master by doing these exercises are that the base of the result relation always changes from that of the input relation when doing a Group operation and there are cases we can try that result in a Bad Group if we are not careful about the columns we choose to identify the result relation.

You have attempted of activities on this page