Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Providing detailed information and counting objects
4. Time-constrained reports
Calculating metrics for multiple business objects
Understanding the difference between various count metrics
Summary

Instruction

Good job! Another common report type is a report on certain objects, often based on a time filter. Take a look:

SELECT
  COUNT(*)
FROM orders
WHERE order_date >= '2016-07-01' AND  order_date < '2016-08-01';

In this query, we count the number of orders placed in July 2016. Note how we used the WHERE clause to get the time limit we're interested in.

Also note that dates in SQL are always placed inside single quotes and are typically formatted as YYYY-MM-DD (i.e., year-month-day). This may be a bit counterintuitive in countries that use other date formats, so watch out. Depending on the exact database engine you use and its configuration, your database may use a different date format. When in doubt, check your database documentation.

Exercise

Count the number of employees hired in 2013. Name the result number_of_employees.

Stuck? Here's a hint!

Use the hire_date column from the employees table.