retagged by
49,751 views
73 73 votes

A relational database contains two tables Student and Performance as shown below:

$$\overset{\text{Table: student}}{\begin{array}{|l|l|} \hline \text{Roll_no} & \text{Student_name}\\\hline 1 & \text{Amit} \\\hline 2 & \text{Priya} \\\hline 3 & \text{Vinit} \\\hline 4 & \text{Rohan} \\\hline 5 & \text{Smita} \\\hline \end{array}} \qquad\overset{\text{Table: Performance}}{\begin{array}{|l|l|l|} \hline \text{Roll_no} & \text{Subject_code} & \text{Marks}\\\hline 1 & \text{A} & 86 \\\hline 1 & \text{B} & 95 \\\hline 1 & \text{C} & 90 \\\hline 2 & \text{A} & 89 \\\hline 2 & \text{C} & 92 \\\hline 3 & \text{C} & 80 \\\hline \end{array}}$$

The primary key of the Student table is Roll_no. For the performance table, the columns Roll_no. and Subject_code together form the primary key. Consider the SQL query given below:

SELECT S.Student_name, sum(P.Marks) 
FROM Student S, Performance P 
WHERE P.Marks >84 
GROUP BY S.Student_name;

The number of rows returned by the above SQL query is ________

8 Answers

Best answer
83 83 votes
Group by Student_name $\implies$ number of distinct values of Student_name

in the instance of the relation all rows have distinct name then it should results $5$ tuples !
edited by
33 33 votes
5 rows

Comma by default means cross product not natural join
27 27 votes
Remember this basic rule in sql

SELECT= PROJECTION

FROM= CROSS PRODUCT

WHERE= SELECT CONDITION

here in the given query we need to take cross product which returns 25 query with keeping in mind the condition to jave marks > 84 so when we group by our answer would be

Amit 452

Priya 452

Vinit 452

Roshan 452

Smita 452

So 5 tuples
12 12 votes

One nice observation - 

$GroupBy()$ with $Having$ Clause  $\Rightarrow$     No. of tuples <= No of Groups

$GroupBy()$ without $Having$ Clause $\Rightarrow$    No. of tuples = No of Groups

5 5 votes

The SQL query performs a cross join between the Student and Performance tables because there is no join condition specified. The WHERE clause filters only the Performance records where Marks > 84

  • Every student is paired with each of those five marks → each student contributes the same five marks to their group.

  • SUM(P.Marks) = 86+95+90+89+92 = 452. So every student gets 452.

Result (what the query actually returns):
 

Student_name
sum(P.Marks)
Amit452
Priya452
Vinit452
Rohan452
Smita452


The query returns 5 rows

0 0 votes
EVERY STUDENT WILL BE MATCHED WITH EVERY OTHER SUBJECT WHERE THE SUBJECT’S  MARKS ARE GREATER THAN 84  NOW WE WILL FIND 5 SUBJECTS HAVING MARKS GREATER THAN 84 THEN 5 STUDENTS WITH 5 SUBJECTS LEADS TO 25 AND FINALLY THEY ARE GROUPED BY STUDENT NAME SO 5 ROWS
Answer:
Position:
Show:

Related questions

57 57 votes
4 answers 4 answers
26.8k
26.8k views
Arjun asked Feb 7, 2019
26,829 views
Consider the following relations $P(X,Y,Z), Q(X,Y,T)$ and $R(Y,V)$.$$\overset{\textbf{Table: P}}{\begin{array}{|l|l|l|} \hline \textbf{X} & \textbf{Y} & \textbf{Z} \\\hli...
52 52 votes
3 answers 3 answers
25.7k
25.7k views
Arjun asked Feb 7, 2019
25,701 views
Let the set of functional dependencies $F=\{QR \rightarrow S, \: R \rightarrow P, \: S \rightarrow Q \}$ hold on a relation schema $X=(PQRS)$. $X$ is not in BCNF. Suppose...
53 53 votes
6 answers 6 answers
28.7k
28.7k views
Arjun asked Feb 7, 2019
28,713 views
Consider the following two statements about database transaction schedules:Strict two-phase locking protocol generates conflict serializable schedules that are also recov...
38 38 votes
3 answers 3 answers
17.6k
17.6k views
Arjun asked Feb 7, 2019
17,603 views
Which one of the following statements is NOT correct about the $B^+$ tree data structure used for creating an index of a relational database table?$B^+$ Tree is a height-...