CS FundamentalsVery hardGATE CS · SQL
Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack', 2000), (106, 'Agra', NULL). What does this query return?
Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack', 2000), (106, 'Agra', NULL).
What does this query return?
SELECT COUNT(*) FROM Acct a WHERE 1 >= (SELECT COUNT(*) FROM Acct b WHERE b.bal > a.bal);
- A. 4
- B. 1
- C. 3
- D. 2
Correct answer: C. 3
2000 has no larger balance and 1500 has one, so both qualify; each 700 has two larger. The trap is account 106: b.bal > NULL is never TRUE, so its inner COUNT is 0 and it qualifies too, giving 3, not 2.
More DBMS and SQL questions
- R(A, B, C, D, E, F) has FDs BF → A, BD → EF, E → CD, CF → B. Each option is a relation schema obtained by projecting R, with the…
- R(A, B, C, D, E, F) has functional dependencies BF → DE, C → E, F → E, DF → B. Which of the following is the complete set of candidate…
- R(A, B, C, D, E) has functional dependencies E → CD, C → A, D → AC. Which decomposition of R is lossless-join?
- Classify the schedule R2(B), W2(B), W1(A), R1(A), W1(B), C1, C2 (Ci = commit of Ti) by the strongest property it satisfies.
- Which statement about the basic timestamp-ordering protocol is correct?
- A file has 20,000 records of 80 bytes stored unspanned in 512-byte blocks, NOT ordered on attribute X. A dense secondary index on X (a…