Skip to main contentSkip to solution

Sales

IDcustomer_idorder_datetotal_amount
1C1012022-01-151000
2C1022022-02-20500
3C1032022-03-10800
4C1012022-04-05600

What is the result of the following query with respect to given relation 'Sales'?

SELECT COUNT(DISTINCT customer_id) FROM Sales;

Solution

✅ Correct Option: 3

COUNT(DISTINCT customer_id) counts each different customer_id only once.

The customer_id values are C101, C102, C103 and C101. C101 appears twice, so the distinct values are C101, C102 and C103, which gives 3\boxed{3}.


Option 4: this is the result of COUNT(customer_id) or COUNT(*), which counts all 4 rows including the repeated C101.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question