nerdexam
Oracle

1Z0-909 · Question #58

The continent column in the country table contains no null values. Examine this output: A. B. C. D.

The correct answer is A. SELECT Continent, Population as pop, COUNT(DISTINCT code) as num_country FROM country GROUP BY Continent ORDER BY Continent. Note: The stated answer of A appears to be an error in this question - the correct answer should be C. Here's why: Why C is correct: SUM(Population) is the proper aggregate function to total population values across all countries per continent. Without SUM(), selecting…

SQL Fundamentals

Question

The continent column in the country table contains no null values. Examine this output:

A. B. C. D.

Exhibits

1Z0-909 question #58 exhibit 1
1Z0-909 question #58 exhibit 2
1Z0-909 question #58 exhibit 3
1Z0-909 question #58 exhibit 4
1Z0-909 question #58 exhibit 5

Options

  • ASELECT Continent, Population as pop, COUNT(DISTINCT code) as num_country FROM country GROUP BY Continent ORDER BY Continent;
  • BSELECT Continent, Population as pop, COUNT(DISTINCT code) as num_country FROM country GROUP BY Continent WITH ROLLUP ORDER BY Continent;
  • CSELECT Continent, SUM(Population) as pop, COUNT(DISTINCT code) as num_country FROM country GROUP BY Continent ORDER BY Continent;
  • DSELECT Continent, SUM(Population) as pop, COUNT(DISTINCT code) as num_country FROM country GROUP BY Continent WITH ROLLUP ORDER BY Continent;

How the community answered

(46 responses)
  • A
    93% (43)
  • B
    2% (1)
  • D
    4% (2)

Explanation

Note: The stated answer of A appears to be an error in this question - the correct answer should be C. Here's why:

Why C is correct: SUM(Population) is the proper aggregate function to total population values across all countries per continent. Without SUM(), selecting Population in a GROUP BY query (as in A and B) is non-deterministic or invalid in standard SQL - it would return an arbitrary single row's population value rather than the continent total.

Why A is wrong: Population is not wrapped in an aggregate function. In a GROUP BY query, every non-grouped column must be aggregated. MySQL's non-strict mode may allow this, but it returns a meaningless arbitrary value, not a continent-wide total.

Why B is wrong: Same non-aggregated Population problem as A, plus WITH ROLLUP generates an extra summary row where Continent is NULL - but the question states Continent has no nulls, so a NULL row in the output would come only from ROLLUP, which doesn't appear in the described output.

Why D is wrong: Although SUM(Population) is correct, WITH ROLLUP adds a grand-total row with Continent = NULL. Since the output being matched doesn't include that extra row, D doesn't match.

Memory tip: The hint "continent has no null values" is your signal - any query using WITH ROLLUP introduces a NULL in the grouping column for the summary row, so you can quickly eliminate B and D. Then ask: "Is the population summed or raw?" - aggregation requires SUM(), eliminating A.

Topics

#NULL handling#aggregation#GROUP BY#column constraints

Community Discussion

No community discussion yet for this question.

Full 1Z0-909 Practice