CS FundamentalsVery hardProduct-company placement · GATE CS
Fee(sid, fee) has rows (1, 500), (2, 700), (3, 700), (4, 400), (5, 900), (6, 400). What does this return? SELECT SUM(fee) FROM Fee f WHERE 3 > (SELECT COUNT(DISTINCT fee) FROM Fee f2 WHERE f2.fee > f.fee);
- A. 2300
- B. 2100
- C. 2800
- D. 3600
Correct answer: C. 2800
A row qualifies if fewer than 3 distinct fees are higher: 900 (0 higher), both 700s (1) and 500 (2) qualify, the 400s (3) do not. Sum = 900 + 700 + 700 + 500 = 2800. 2300 is what COUNT(*) instead of COUNT(DISTINCT) gives, and 2100 adds each distinct value once.
More DBMS and SQL questions
- Player(pid, team, runs) has rows (1, 'A', 50), (2, 'A', 70), (3, 'A', 70), (4, 'B', 40), (5, 'B', NULL), (6, 'B', 90), (7, 'C', NULL)…
- Cust(cid, city) has rows (1, 'Pune'), (2, 'Delhi'), (3, NULL), (4, 'Pune'). What are the values of Q1: SELECT COUNT() FROM (SELECT city…
- Ord(oid, cid, amt) has no row with cid = 99. What do these return? Q1: SELECT SUM(amt), COUNT() FROM Ord WHERE cid = 99; Q2: SELECT cid…
- R(A, B, C, D, E, F) has functional dependencies AB → C, C → D, D → E, E → A and F → B. How many superkeys does R have?
- R(A, B, C, D, E, F) has functional dependencies A → BC, CD → E, E → A and B → F. It is decomposed into R1(A, B, C, F) and R2(A, C, D, E)…
- R(A, B, C, D, E) has functional dependencies A → C, B → D and CD → E. It is decomposed into R1(A, C), R2(B, D) and R3(A, B, E). Is the…