Let’s examine the query to count signups after 1, Jan 2018:
SELECT COUNT(*)
FROM users
WHERE
signup_date > '2018-01-01'
We used the greater than >non-inclusive operator. Non-inclusive means that signup dates that are exactly '2018-01-01' will be filtered out and we won’t see them in the query’s output
If we want to keep signups from 1st of January we should use inclusive comparison operator greater or equals than >=:
SELECT COUNT(*)
FROM users
WHERE
signup_date >= '2018-01-01'
Same with numbers, if we want to calculate users who are younger than 50 we can use less than < operator:
SELECT COUNT(*)
FROM users
WHERE
age < 50
but this query won’t include users who are exactly 50 years old. If we want to filter for 50-year-olds as well we should use less than or equals operator:
SELECT COUNT(*)
FROM users
WHERE
age <= 50
Keep an eye for such issues Imagine a company had a sale on the last day of the month. Someone calculates monthly revenue and by mistake doesn’t include the last day of the month – the highest revenue day will be excluded from the analysis.
Before you go to the next lesson go and play with inclusive and non-inclusive comparison operators in the Playground and see how counts will differ.
SQL Habit is a course (or, as some of the students say, “business simulator”). It’s based on a story of a fictional startup called Bindle. You’ll play a role of their Data Analyst and solve real-life challenges from Business, Marketing, and Product Management.
SQL Habit course is made of bite-sized lessons (you’re looking at one atm) and exercises. They always have a real-life setting and detailed explanations. You can immediately apply everything you’ve learned at work.
“well worth the money”
Fluent in SQL in a month
Master Data Analysis with SQL with real life examples from Product Management, Marketing, Finance and more.