CS FundamentalsHardAmazon/Flipkart SQL round · GATE CS
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?
DELETE FROM Acct WHERE bal < (SELECT AVG(bal) FROM Acct a2 WHERE a2.branch = Acct.branch); SELECT COUNT(*) FROM Acct;
- A. 6
- B. 5
- C. 3
- D. 4
Correct answer: B. 5
Branch averages (NULL ignored): Agra 1000, Bhopal 700, Cuttack 2000. Only account 101 (500 < 1000) is deleted. The NULL-balance account is not deleted because NULL < 1000 is unknown. 5 rows remain.
More DBMS and SQL questions
- Which ACID property is primarily the responsibility of the application programmer (together with declared integrity constraints), rather…
- R(A, B, C, D, E) has functional dependencies DE → B, CE → A, AC → BE. How many superkeys does R have?
- Σ = {C → A, AB → D, BC → D, A → B, D → B} on R(A, B, C, D, E). Exactly one FD in Σ is redundant (it can be derived from the others). Which…
- R(A, B, C, D, E, F) has functional dependencies B → ACDF, A → B. How many superkeys does R have?
- R(A, B) = {(2, 1), (3, 1), (3, 3), (3, 4), (4, 4)} and S(B, C) = {(1, 5), (2, 5), (2, 7), (3, 7)}. How many tuples are in R ⟕ S (left…
- A relation has 100,000 tuples and a selection σ{city='Pune'} with an estimated selectivity of 2%. Each block holds 50 tuples and the…