Ravindra BagaleCourses & study guides Track your progress

11. Aggregate Functions: SUM COUNT AVG MIN MAX

11.3 COUNT(*) vs COUNT(DISTINCT column)

का (Why). ऑर्डर्स मोडणे vs युनिक customers मोडणे — वेगळे प्रश्न.

काय (What). COUNT(*) = रो. COUNT(DISTINCT col) = त्या कॉलममधील युनिक मूल्ये.

कसं (How). SELECT COUNT(*) , COUNT(DISTINCT customer_id) FROM orders;

पायऱ्या

  1. ऑर्डर्स.
  2. ऑर्डर करणारे युनिक customers.
  3. फरक समजावा.

उदाहरणे

उदाहरण 1 · dataset: raja_coffee

SELECT COUNT(*) AS orders,
       COUNT(DISTINCT customer_id) AS unique_customers,
       COUNT(DISTINCT city) AS unique_cities
FROM orders;

Output

ordersunique_customersunique_cities
2486

Meaning. ऑर्डर्स vs लोक vs शहरे.

Ravindra Bagale's Tip

COUNT(DISTINCT …) is slower on huge tables — fine on practice sizes.