CS FundamentalsModerateGATE CS (PYQ pattern)
Table K(a, b): (0,5), (3,7), (0,NULL), (NULL,4), (2,NULL), (0,0). What does SELECT SUM(COALESCE(NULLIF(a, 0), b)) FROM K return?
- A. 9
- B. 14
- C. 5
- D. 19
Correct answer: B. 14
NULLIF(a, 0) turns a = 0 into NULL, then COALESCE falls back to b: rows give 5, 3, NULL, 4, 2, 0 and the NULL is skipped by SUM: 14. Using COALESCE(a, b) directly would give 9.
More DBMS and SQL questions
- ORD(oid, amt): (1,100), (2,200), (3,300). LN(oid, item): (1,a), (1,b), (1,c), (2,a), (3,b), (3,c). PAY(oid, paid): (1,40), (1,60)…
- EM(id, sal, mgr): (1,90,NULL), (2,70,1), (3,70,1), (4,95,2), (5,60,2), (6,40,3), (7,80,3), (8,NULL,4), (9,85,7). How many rows does SELECT…
- Table UP(a, b): (1,10), (2,20), (3,30). After UPDATE UP SET a = b, b = a; (standard SQL semantics), what is the sum of column a and the…
- Table DU(a, b): (1,NULL), (1,NULL), (2,3), (2,3), (NULL,5), (NULL,5), (1,2). Let x = rows returned by SELECT DISTINCT a, b FROM DU, y =…
- R(A, B) and S(B) are relations. Which relational-algebra expression computes the division R ÷ S (the A-values that are paired in R with…
- R(A, B): (1,x), (2,y), (3,z), (4,NULL). S(B, C): (x,10), (x,11), (y,20), (w,30), (NULL,40). How many rows does SELECT FROM R FULL OUTER…