Summary
Lesson Summary: SQL Aggregation and Count Function
In this lesson, we revisited the aggregation functions in SQL, particularly the COUNT
function, focusing on a practical example using the city table.
Objective
We aimed to count the number of cities in the city
table that have a population greater than 100,000.
Steps Undertaken
-
Initial Query: We started by retrieving all rows and columns from the
city
table using:SELECT * FROM city;
-
Filtering Data: To focus only on cities with populations greater than 100,000, we added a
WHERE
clause:WHERE population > 100000;
-
Counting Rows: To count the number of qualifying cities, we used the
COUNT
function:SELECT COUNT(*) FROM city WHERE population > 100000;
-
Outcome: Upon executing the query, we determined that there are six cities in the database with populations exceeding 100,000.
Conclusion
This lesson illustrated the application of the COUNT
function in SQL while performing a simple aggregation task based on population criteria.