Interview › COUNT DISTINCT
SQL interview: COUNT(*) vs COUNT(col) vs COUNT DISTINCT
COUNT(*) is rows. COUNT(col) skips NULL. COUNT(DISTINCT col) skips NULL and doubles.
Prompt. How many orders, how many with an email, how many different customers.
Hint: COUNT(*), COUNT(email), COUNT(DISTINCT customer_id)
SELECT COUNT(*) AS orders,
COUNT(email) AS with_email,
COUNT(DISTINCT customer_id) AS customers
FROM Orders;
COUNT(DISTINCT) + another DISTINCT is usually two questions, not one fancy COUNT.
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free