Bird
0
0

Which of the following is the correct syntax to count distinct non-NULL values in the column customer_id from the table sales?

easy📝 Syntax Q3 of 15
SQL - Aggregate Functions
Which of the following is the correct syntax to count distinct non-NULL values in the column customer_id from the table sales?
ASELECT COUNT(customer_id DISTINCT) FROM sales;
BSELECT COUNT(DISTINCT(customer_id) FROM sales;
CSELECT COUNT(DISTINCT) FROM sales;
DSELECT COUNT(DISTINCT customer_id) FROM sales;
Step-by-Step Solution
Solution:
  1. Step 1: Recall syntax for counting distinct values

    The correct syntax is COUNT(DISTINCT column_name) without extra parentheses.
  2. Step 2: Check each option

    SELECT COUNT(DISTINCT customer_id) FROM sales; uses correct syntax; A and C are invalid; D has extra parentheses which is invalid in standard SQL.
  3. Final Answer:

    SELECT COUNT(DISTINCT customer_id) FROM sales; -> Option D
  4. Quick Check:

    COUNT(DISTINCT column) syntax is correct [OK]
Quick Trick: Use COUNT(DISTINCT column) to count unique non-NULL values [OK]
Common Mistakes:
MISTAKES
  • Placing DISTINCT after column name
  • Using COUNT(DISTINCT) without column
  • Adding extra parentheses around column

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes