0% found this document useful (0 votes)
8 views2 pages

Quiz 2 CS311 S2 Solution

The document contains a quiz for CSE-311 with questions related to SQL queries and database schema involving social groups, pictures, and friendships. It includes tasks to write SQL queries to identify 'cool persons' with at least 40 friends, troubleshoot invalid SQL commands, and create a view for salespeople in Paris. The quiz is structured with specific marks allocated for each question and requires detailed explanations and SQL syntax from the students.

Uploaded by

anuraf3thmedia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Quiz 2 CS311 S2 Solution

The document contains a quiz for CSE-311 with questions related to SQL queries and database schema involving social groups, pictures, and friendships. It includes tasks to write SQL queries to identify 'cool persons' with at least 40 friends, troubleshoot invalid SQL commands, and create a view for salespeople in Paris. The quiz is structured with specific marks allocated for each question and requires detailed explanations and SQL syntax from the students.

Uploaded by

anuraf3thmedia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: __________________________ ID: _______________________ Date: 14/11/2024

CSE-311 Quiz: 2 Total Marks -7.5 Time- 45 minutes


Faculty: NLH

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

The schema is:


MEMBER (personName, groupName)
PICTURE (groupName, picture) /* picture = primary key */
FRIEND (personName1, personName2)

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

HAVING (COUNT(*) >= 40)

Another solution:

SELECT personName1

FROM friend

GROUPBY personName1

HAVING (COUNT(DISTINCT personName2) >= 40)


2. We tried to execute the following query and discovered it would not work because 2 marks
it was not valid SQL:

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.

View SQL Syntax____________________________ View Output_______________________________


CREATE VIEW newyorkstaff /*can be any name*/ salesman_id name city commission
AS SELECT * 5002 Nail Paris 0.13
Knite
FROM salesman 5006 Mc Lyon Paris 0.14
WHERE city = 'Paris’;

You might also like