Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Limiting the output
Eliminating duplicate results
Aggregation
13. Count the rows, ignore the NULLS
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

Naturally, the asterisk (*) isn't the only argument you can pass in to the COUNT() function. For example, we may ask the database to count the values in a specific column:

SELECT
  COUNT(CustomerId) AS CustomerNumber
FROM Order;

What's the difference between COUNT(*) and COUNT(CustomerId)? Well, the first option counts all rows in the table, and the second option counts all rows where the column CustomerId has a specified value. In other words, if there is a NULL in the CustomerId, it won't be counted.

Exercise

Check how many non-NULL values in the column Position there are in the table Employee. Name the column PositionNumber.

Stuck? Here's a hint!

Type:

SELECT
  COUNT(Position) AS PositionNumber
FROM Employee;