Back-To-School 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 about the difference between COUNT(*) and COUNT(ColumnName). 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
  ShipCountry,
  COUNT(*) AS AllOrders,
  COUNT(ShippedDate) AS ShippedOrders
FROM Orders
GROUP BY ShipCountry;

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

Exercise

Count the number of customers with and without a fax number. Show two columns: AllCustomersCount and CustomersWithFaxCount.

Stuck? Here's a hint!

Use COUNT(*) and COUNT(Fax).