CS FundamentalsHardGATE CS (PYQ pattern)
EM(id, sal, mgr): (1,90,NULL), (2,70,1), (3,70,1), (4,95,2), (5,60,2), (6,40,3), (7,80,3), (8,NULL,4), (9,85,7). How many rows does SELECT e.id FROM EM e JOIN EM m ON e.mgr = m.id JOIN EM g ON m.mgr = g.id WHERE e.sal > g.sal return (employees who earn more than their manager's manager)?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Employees with a grand-manager: 4, 5, 6, 7 (grand-manager 1, salary 90), 8 (grand-manager 2, 70) and 9 (grand-manager 3, 70). 4 (95 > 90) and 9 (85 > 70) qualify; 8 has a NULL salary, so the comparison is UNKNOWN and the row is dropped. Answer 2. Comparing with the direct manager instead gives 3 (4, 7 and 9).
More DBMS and SQL questions
- Table UP(a, b): (1,10), (2,20), (3,30). After UPDATE UP SET a = b, b = a; (standard SQL semantics), what is the sum of column a and the…
- Table DU(a, b): (1,NULL), (1,NULL), (2,3), (2,3), (NULL,5), (NULL,5), (1,2). Let x = rows returned by SELECT DISTINCT a, b FROM DU, y =…
- R(A, B) and S(B) are relations. Which relational-algebra expression computes the division R ÷ S (the A-values that are paired in R with…
- R(A, B): (1,x), (2,y), (3,z), (4,NULL). S(B, C): (x,10), (x,11), (y,20), (w,30), (NULL,40). How many rows does SELECT FROM R FULL OUTER…
- R(A, B) = {(1,2), (1,3), (2,3), (3,4), (4,1)} is a graph's edge set. How many tuples are in the relation π{A,D}(ρ(R) ⋈{R.B = R2.A} ρ(R2))…
- Multiple-granularity locking (modes IS, IX, S, SIX, X with the standard compatibility matrix). T1 holds IX on table TB and S on row r1 of…