CS FundamentalsVery hardGATE CS · SQL
Table Att(emp, day, status) rows: ('u', 1, 'P'), ('u', 2, 'P'), ('u', 3, 'A'), ('u', 4, 'P'), ('u', 5, 'P'), ('u', 6, 'P'), ('v', 1, 'A'), ('v', 2, 'P'), ('v', 3, 'P'), ('v', 4, 'A'), ('v', 5, 'P'). What does this query return?
Table Att(emp, day, status) rows: ('u', 1, 'P'), ('u', 2, 'P'), ('u', 3, 'A'), ('u', 4, 'P'), ('u', 5, 'P'), ('u', 6, 'P'), ('v', 1, 'A'), ('v', 2, 'P'), ('v', 3, 'P'), ('v', 4, 'A'), ('v', 5, 'P').
What does this query return?
SELECT COUNT(*) FROM (
SELECT status,
LAG(status) OVER (PARTITION BY emp ORDER BY day) AS prev
FROM Att) x
WHERE status <> prev;- A. 5
- B. 7
- C. 4
- D. 6
Correct answer: A. 5
u's sequence P P A P P P changes twice (day 3 and day 4); v's A P P A P changes three times (days 2, 4, 5). Each employee's first row has prev = NULL, so status <> NULL is unknown and not counted: 5.
More DBMS and SQL questions
- Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this…
- Classify the schedule W3(B), R2(A), R3(B), W2(A), W1(B), R1(B).
- In a B+ tree every internal node can have at most 34 children and every leaf can hold at most 30 keys. With exactly 4 levels (root at…
- Table Stu(sid, sname) rows: (1, 'Om'), (2, 'Pia'), (3, 'Raj'), (4, 'Sia'). Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2'…
- Relations R (1000 blocks) and S (500 blocks) are joined with block nested-loop join using M = 22 buffer blocks (M − 2 for the outer…
- T1: W1(A), W1(B) and T2: R2(A), R2(B). Of all 6 interleavings that keep each transaction's own order, how many are conflict serializable?