
Answer-first summary for fast verification
Answer: 3 6 5
The query calculates three counts: count_a uses `count_if(col1 > 1)`, which counts rows where col1 is greater than 1. The data has values 0, 1, 2, NULL, 2, 3 (assuming 6 rows). Values >1 are 2, 2, 3 → 3. count_b is `count(*)`, which counts all 6 rows. count_c is `count(col1)`, which skips NULL, resulting in 5 non-NULL values. Thus, the output is 3, 6, 5 (Option A).
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
How can the count_if function and counting NULL values be utilized in the following scenario?
Given a table random_values with the data below, what would be the output of this query?
SELECT
count_if(col1 > 1) AS count_a,
count(*) AS count_b,
count(col1) AS count_c
FROM random_values
SELECT
count_if(col1 > 1) AS count_a,
count(*) AS count_b,
count(col1) AS count_c
FROM random_values
Data in random_values:
0
1
2
NULL
2
3
0
1
2
NULL
2
3
A
3 6 5
B
4 6 5
C
3 6 6
D
4 6 6
No comments yet.