Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Providing detailed information and counting objects
Calculating metrics for multiple business objects
Understanding the difference between various count metrics
11. Review of the COUNT() function
Summary

Instruction

Well done! When creating business reports, you should remember the difference between COUNT(*) and COUNT(column_name). Suppose we want to find the number of orders to be shipped to each country and the number of orders already shipped. Take a look at the query below:

SELECT
  ship_country,
  COUNT(*) AS all_orders,
  COUNT(shipped_date) AS shipped_orders
FROM orders
GROUP BY ship_country;

COUNT(*) will count all orders in ship_country. COUNT(shipped_date) will count only the rows where the shipped_date column value is not NULL. In our database, a NULL in the shipped_date column means an order hasn't been shipped yet. In other words, COUNT(shipped_date) only counts orders that have already been shipped.

Exercise

Count the number of customers with and all those without a fax number. Show two columns: all_customers_count and customers_with_fax_count.

Stuck? Here's a hint!

Use COUNT(*) and COUNT(fax).