Quiz 2 CS311 S2 Solution
Quiz 2 CS311 S2 Solution
1. Consider a database of social groups that allows people to become members 3.5 marks
of groups:
a. a person can be a member of several groups
b. each group maintains a list of pictures that are accessible to all members
c. In addition to the groups, the database also maintains a list of friends
PICTURE stores the name of the group and a corresponding picture that the group owns.
The FRIEND table is symmetric, i.e. if X is friend with Y then Y is friend with X.
Every person is a member of at least one group.
A “cool person” is one that has at least 40 friends. Write a SQL query that returns all the cool
persons in the database. You need to write a SQL query that computes a list of names.
First solution:
SELECT personName1
FROM friend
GROUPBY personName1
Another solution:
SELECT personName1
FROM friend
GROUPBY personName1
Explain in detail what the problem(s) is and how to fix it. You need to explain exactly what makes
this an illegal SQL command. Then explain how to fix the bug(s) to get a SQL command that does
the same thing as the original one but does it legally.
The attribute P.pname in the SELECT clause does not appear in the GROUP BY clause as either
an attribute name or the named result of an aggregate function. The easiest fix is to add
P.pname to the GROUP BY clause.
3. From the following table, a) write SQL syntax to create a view with the relevant 2 marks
salespeople information who belong to the city of Paris.
b) Show what would be the output from the view.