Databricks Data Engineer Associate Question 118
Single answerYou are tasked with analyzing a dataset in Databricks that contains a column 'sales'. This column includes numeric values and some NULL entries. Which of the following statements accurately describes the behavior of the count() function when applied to the 'sales' column?
- A
The
count(sales)function includes NULL values in its count. - B
The
count(sales)function skips NULL values and counts only non-NULL values. - C
The
count(sales)function returns 0 if the column contains any NULL values. - D
The
count(*)function skips NULL values in the 'sales' column.
Show answer and explanation
Correct answer: B
Explanation
The count(column_name) function in SQL and Spark skips NULL values in the specified column and counts only rows with non-NULL values. In this scenario, the count(sales) function will count only the rows where the 'sales' column has a value. On the other hand, count(*) counts all rows, regardless of NULL values in specific columns.
- A. Incorrect.
Incorrect. The
count()function does not include NULL values in its count. It only counts non-NULL values. - B. Correct.
Correct. The
count(sales)function skips NULL values and counts only the rows where the 'sales' column has non-NULL values. - C. Incorrect.
Incorrect. The
count()function does not return 0 just because the column contains NULL values; it counts the rows with non-NULL values. - D. Incorrect.
Incorrect. The
count(*)function counts all rows in the dataset, including those with NULL values in the 'sales' column.