914 views
0 0 votes
Consider the following ORACLE relations:
R(A,B,C)={〈1,2,3〉,〈1,2,0〉,〈1,3,1〉,〈6,2,3〉,〈1,4,2〉,〈3,1,4〉 }
S(B,C,D)={〈2,3,7〉,〈1,4,5〉,〈1,2,3〉,〈2,3,4〉,〈3,1,4〉 }
Consider the following two SQL queries
SQ1: SELECT R.B,AVG(S.B)
FROM R,S
WHERE S.A=S.C AND S.D<7
GROUP BY R.B;
SQ2: SELECT DISTINCT S.B,MIN(S.C)
FROM S GROUP BY S.B
HAVING COUNT (DISTINCT S.D)>1;
If M is the number of tuples returned by SQ1 and N is the number of tuples returned by SQ2 then M=______,N=______ .

1 Answer

2 2 votes

SQ1: {Correction done in bold}

SELECT R.B,AVG(S.B)
FROM R,S
WHERE R.A=S.C AND S.D<7
GROUP BY R.B;

o/p :

R.B AVG(S.B)
1 2
2 3
3 3
4 3

M=4

SQ2:

SELECT DISTINCT S.B,MIN(S.C)
FROM S GROUP BY S.B
HAVING COUNT (DISTINCT S.D)>1;

O/P:

S.B MIN(S.C)
1 2
2 3

N=2

Position:
Show:

Related questions

1 1 vote
1 answers 1 answer
1.2k
1.2k views
tishhaagrawal asked Dec 16, 2023
1,195 views
My doubt here is, if NOT EXISTS gets an empty set as the input then every tuple of the table in the outer query must satisfy the condition. Am I right?For example, in the...
2 2 votes
1 1 answer
752
752 views
equimanthorn asked Sep 15, 2023
752 views
A SQL query is written in its format as clauses are arranged in a specific sequence and these clauses are executed in different sequence. If we’re writing a query using s...
0 0 votes
1 1 answer
1.8k
1.8k views
rayhanrjt asked Jan 6, 2023
1,812 views
Write SQL command to find DepartmentID, EmployeeName from Employee table whose average salary is above 20000.
2 2 votes
1 1 answer
850
850 views
Subhrangsu asked Jun 18, 2022
850 views
Write SQL query to show all employees hired on June 4,1984 (non-default format)emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)