CS FundamentalsHardAmazon/Flipkart SQL round · GATE CS
Table Score(name, pts) rows: ('a', 90), ('b', 85), ('c', 90), ('d', 70), ('e', 85), ('f', 60). In this query's output, what are (r, dr) for d and for f?
Table Score(name, pts) rows: ('a', 90), ('b', 85), ('c', 90), ('d', 70), ('e', 85), ('f', 60).
In this query's output, what are (r, dr) for d and for f?
SELECT name, RANK() OVER (ORDER BY pts DESC) AS r,
DENSE_RANK() OVER (ORDER BY pts DESC) AS dr
FROM Score
ORDER BY pts DESC, name;- A. d: (5, 5), f: (6, 6)
- B. d: (4, 3), f: (5, 4)
- C. d: (3, 3), f: (4, 4)
- D. d: (5, 3), f: (6, 4)
Correct answer: D. d: (5, 3), f: (6, 4)
Scores in order: 90, 90, 85, 85, 70, 60. RANK leaves gaps after ties (1, 1, 3, 3, 5, 6); DENSE_RANK does not (1, 1, 2, 2, 3, 4). So d = (5, 3) and f = (6, 4).
More DBMS and SQL questions
- R(A, B, C, D, E, F) has the set of functional dependencies Σ = {A → D, E → C, AE → CD, F → B, B → F}. Which of the following FDs is NOT in…
- R(A, B, C, D) has functional dependencies D → AB, A → BC. What is the highest normal form R satisfies?
- A B+ tree index uses 512-byte blocks, 8-byte search keys, 4-byte block pointers and 6-byte record (data) pointers. Each leaf also keeps…
- R(A, B) = {(1, 3), (3, 2), (3, 4), (4, 2)} and S(B, C) = {(2, 5), (2, 7), (3, 6), (3, 7), (4, 5)}. How many tuples does σ{R.B ≠ S.B}(R ×…
- A query optimizer rewrites σ{city='Pune'}(Customer ⋈ Orders) as σ{city='Pune'}(Customer) ⋈ Orders, where city is an attribute of Customer…
- Which change is an example of PHYSICAL data independence in the three-schema architecture?