CS FundamentalsVery hardProduct-company placement

Ord(oid, cid, amt) has no row with cid = 99. What do these return? Q1: SELECT SUM(amt), COUNT(*) FROM Ord WHERE cid = 99; Q2: SELECT cid, COUNT(*) FROM Ord WHERE cid = 99 GROUP BY cid;

  1. A. Q1: one row (NULL, 0); Q2: no rows
  2. B. Q1: one row (0, 0); Q2: one row (99, 0)
  3. C. Q1: no rows; Q2: no rows
  4. D. Q1: one row (NULL, 0); Q2: one row (99, 0)

Correct answer: A. Q1: one row (NULL, 0); Q2: no rows

An aggregate without GROUP BY always yields exactly one row: SUM of nothing is NULL and COUNT(*) is 0. With GROUP BY, there are no groups at all, so Q2 returns no rows.

More DBMS and SQL questions

Exams that ask this topic