13. Count signups from country

"That’s so cool that we helped that user to log in, she indeed purchased a subscription, so awesome! But I still want to know how many users signed up from Germany 😄" said Gessica.

So far we’ve learned how to filter all user records from Germany ✅. Instead of counting all records by hand, we can ask SQL to count it for us. Here’s the query:

SELECT 
  COUNT(*)
FROM users
WHERE
  country = 'de'

As you can see it’s our normal query to select all records but instead of selecting all columns (*) we use SQL aggregate function COUNT.

Aggregate functions 🙈

It’s helpful to think about the query above ☝ as a usual SELECT * query which filters all records and then aggregates them. Instead of printing all records, it gives us a single number, aggregated value, calculated from all filtered records. SQL provides an aggregate function to count, sum, calculate min/max/average values, and more. Later in the course, we’ll use these functions to answer questions like “Min/max/average user age”, “Average revenue per user” and so on.

Let’s look closer at function syntax: COUNT(*). COUNT is a function name and * is the argument of a function. Usually, the argument is a column name or a wildcard symbol * (meaning all columns). Here’s another example of an aggregate function: MIN(age):

SELECT 
  MIN(age)
FROM users
WHERE
  country = 'de'

This query filters users from Germany and then it aggregates all of those users by finding the one with minimum age and printing it for us. Aggregate functions are vital for reporting in Marketing or Product Management – we’re measuring a number of signups, sums or averages of revenues. We’ll see many examples of aggregate functions in the SQL Habit course. It’s time for practice! 🚀

Anatoli Makarevich, author of SQL Habit About SQL Habit

Hi, it’s Anatoli, the author of SQL Habit. 👋

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.
-- Type your query here, for example this one -- lists all records from users table: SELECT * FROM users
LIMIT 500
Loading chart... ⏳