CS FundamentalsVery hardTCS Digital · Infosys SP · GATE CS
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 emp, COUNT(*)
FROM Att a
WHERE status = 'P'
AND NOT EXISTS (SELECT * FROM Att b
WHERE b.emp = a.emp AND b.day = a.day - 1
AND b.status = 'P')
GROUP BY emp
ORDER BY emp;- A. (u, 5), (v, 3)
- B. (u, 1), (v, 1)
- C. (u, 2), (v, 1)
- D. (u, 2), (v, 2)
Correct answer: D. (u, 2), (v, 2)
A present day with no present day immediately before it starts a streak. u: days 1 and 4 start streaks; v: days 2 and 5. So each has 2 streaks of presence.
More DBMS and SQL questions
- Which of the following is NOT one of the anomalies that normalisation into BCNF is meant to remove?
- Under the write-ahead logging (WAL) rule, which ordering must hold?
- A B+ tree index uses 2048-byte blocks, 14-byte search keys, 8-byte block (tree) pointers and 10-byte record pointers. What is the maximum…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- R(A, B, C, D, E, F) has the set of functional dependencies Σ = {E → ABF, F → BE, C → F, B → C}. Which of the following FDs is NOT in Σ⁺…
- R(A, B, C, D, E, F) has functional dependencies C → AD, A → D, D → C. What is the highest normal form R satisfies?