CS FundamentalsVery hardGATE CS · Amazon SQL round
EMP has salaries 300, 200, 200, 200, 150, 100 for six employees. Let QR select employees whose RANK() OVER (ORDER BY sal DESC) equals 3, and QD select employees whose DENSE_RANK() OVER (ORDER BY sal DESC) equals 3. The numbers of rows returned by QR and QD are respectively:
- A. 3 and 1
- B. 1 and 1
- C. 0 and 1
- D. 1 and 3
Correct answer: C. 0 and 1
RANK leaves gaps after ties: ranks are 1, 2, 2, 2, 5, 6, so no row has rank 3. DENSE_RANK gives 1, 2, 2, 2, 3, 4, so exactly one row (salary 150) has dense rank 3.
More DBMS and SQL questions
- R(A, B, C, D, E) has the functional dependencies A → B, BC → D, D → E and E → A. The number of candidate keys of R and its highest normal…
- Consider the schedule S: r1(A) r3(B) r2(C) w2(A) r4(C) w4(B) r1(D) r3(D), where ri/wi is a read/write by transaction Ti. How many distinct…
- A B+ tree on 8-byte keys uses 4096-byte blocks. An internal node holds p tree pointers (8 bytes each) and p − 1 keys. A leaf holds q (key…
- E(id, dept) = (1, 10), (2, 10), (3, 20), (4, 30), (5, NULL), (6, 20), (7, 40) and D(did, loc) = (10, X), (20, Y), (20, X), (30, Y), (50…
- S(v) holds the nine rows 10, 20, 20, 30, 30, 30, 40, 40, 50. The query SELECT SUM(v) OVER (ORDER BY v) FROM S uses the default frame. What…
- Emp(id, dept, sal) = (1, A, 50), (2, A, 70), (3, A, NULL), (4, B, 40), (5, B, 60), (6, B, 60), (7, NULL, 90), (8, C, 30). How many rows…