CS FundamentalsModerateGATE CS · PSU (ISRO/BARC)
A query must list departments whose average salary exceeds 50000, considering only employees hired after 2020. Which clause placement is correct?
- A. Hiring filter in WHERE, average test in HAVING
- B. Both conditions in HAVING with no WHERE
- C. Both conditions in WHERE
- D. Average test in WHERE, hiring filter in HAVING
Correct answer: A. Hiring filter in WHERE, average test in HAVING
WHERE filters rows before grouping and cannot contain aggregates; HAVING filters groups and is where AVG(salary) > 50000 belongs. Putting a per-row filter in HAVING is invalid unless it is grouped.
More DBMS and SQL questions
- 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) has functional dependencies CE → A, A → CE, BE → A, BC → E, E → BC. What is the highest normal form R satisfies?
- A transaction has executed its final statement, but its commit record is not yet on stable storage. Which state is it in?
- R(A, B, C, D, E, F) has functional dependencies EF → D, B → C, D → BF, A → E. How many superkeys does R have?
- 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…
- R(A, B, C, D, E) with functional dependencies E → BC, D → B is decomposed into R1(A, B, D), R2(C, D), R3(B, C, E). Which statement is…