MySQL Essential Training
Illustration by Don Barnett

MySQL Essential Training

with Bill Weinman

Video: Aggregate functions

Aggregate functions are functions that operate on a So, I'll select COUNT with an asterisk in the parenthesis. And when I press go, you see there are 239 rows in the country table.
Expand all | Collapse all
  1. 4m 22s
    1. Welcome
      1m 3s
    2. Using the exercise files
      1m 31s
    3. What is MySQL?
      1m 48s
  2. 45m 37s
    1. Installation overview
      3m 16s
    2. Installing XAMPP on Windows
      5m 55s
    3. Installing XAMPP on the Mac
      6m 38s
    4. Setting up MySQL users
      11m 31s
    5. Installing SID on Windows
      5m 43s
    6. Installing SID on the Mac
      6m 6s
    7. Installing time zone support in MySQL on Windows
      6m 28s
  3. 45m 43s
    1. The SELECT statement
      3m 57s
    2. Selecting rows
      4m 57s
    3. Selecting columns
      3m 8s
    4. Sorting results with ORDER BY
      2m 58s
    5. Filtering results with WHERE
      3m 52s
    6. Filtering results with LIKE and IN
      3m 41s
    7. Filtering results with regular expressions
      8m 21s
    8. Inserting rows
      4m 9s
    9. Updating rows
      2m 21s
    10. Deleting rows
      2m 25s
    11. Literal strings
      3m 12s
    12. Understanding NULL
      2m 42s
  4. 41m 47s
    1. Creating a database
      4m 30s
    2. Creating a table
      7m 18s
    3. Creating indexes
      6m 8s
    4. Controlling column behavior with constraints
      4m 46s
    5. Creating an ID column
      6m 58s
    6. Using foreign key constraints
      7m 58s
    7. Altering a table
      4m 9s
  5. 28m 56s
    1. What are data types?
      4m 1s
    2. Numeric types
      5m 21s
    3. String types
      2m 58s
    4. Date and time types
      7m 2s
    5. Bit type
      2m 26s
    6. Boolean values
      2m 15s
    7. Enumeration types
      4m 53s
  6. 32m 34s
    1. String functions
      6m 57s
    2. Numeric functions
      6m 2s
    3. Date and time functions
      4m 12s
    4. Time zones in MySQL
      3m 37s
    5. Formatting dates
      1m 51s
    6. Aggregate functions
      5m 45s
    7. Flow control with CASE
      4m 10s
  7. 7m 6s
    1. Maintaining database integrity with transactions
      4m 46s
    2. Using transactions for performance
      2m 20s
  8. 16m 49s
    1. Updating a table with a trigger
      5m 11s
    2. Preventing automatic updates with a trigger
      7m 29s
    3. Logging transactions with a trigger
      4m 9s
  9. 14m 11s
    1. Creating a simple subselect
      3m 23s
    2. Searching within a result set
      3m 53s
    3. Creating a view
      3m 32s
    4. Creating a joined view
      3m 23s
  10. 12m 26s
    1. Understanding MySQL stored routines
      2m 0s
    2. Creating a stored function
      4m 34s
    3. Creating a stored procedure
      5m 52s
  11. 14m 4s
    1. The multi-platform PDO interface
      3m 44s
    2. Executing the SQL
      4m 8s
    3. Implementing auto-increment IDs
      2m 3s
    4. Using a stored funciton
      4m 9s
  12. 1m 3s
    1. Goodbye
      1m 3s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course MySQL Essential Training
4h 24m Beginner May 14, 2014

Viewers: in countries Watching now:

MySQL is by far the most popular database management system for small- to medium-sized web projects. In this course, Bill Weinman provides clear, concise tutorials that guide you through creating and maintaining a MySQL database of your own. Bill explores the basic syntax, using SQL statements to create, insert, update, and delete data from your tables. He also covers creating a new database from scratch, as well as data types, transactions, subselects, views, and stored routines. Plus, learn about the multi-platform PHP PDO interface that will help you connect your database to web applications.

Topics include:
  • Writing queries
  • Creating and updating databases and tables
  • Using MySQL built-in functions
  • Sorting and filtering data
  • Updating tables with triggers
  • Working with subselects and views
  • Creating and using a stored function
Bill Weinman

Aggregate functions

Aggregate functions are functions that operate on a set of rows rather than row by row. For example, we'll be using the world database. And we'll start with a simple example of an aggregate function that we're all familiar with the Count function. So, I'll select COUNT with an asterisk in the parenthesis. FROM the country table. And when I press go, you see there are 239 rows in the country table. So this returns one result for a number of rows.

There's 239 rows but there's only one result for the count. The asterisk is a special case for the count function that will count all the rows in a table. If instead, you specify a column. COUNT will count all the non-null values in that column. So if I put in here population, which I know has a view null values in it, you notice we get a smaller value; instead of 239 we get 232. And those are the non-null values in the population column.

The GROUP BY clause, I'll put an asterisk back in over here and we'll specify a group by may be used to group rows for use with aggregate functions. So if I say, GROUP BY, continent et all. Put continent over here so we can see which continent we're looking at. So this will group our results by continent and give account for each group. And I want to order it by count.

So I'm going to give this an alias with as count,. And I'll order by count descending, so that they're in descending order of count. And so we're gong to get one row in the result for each continent, with a count of how many rows there are in that continent. And it'll be ordered by that count in descending order. So when I press Go here, here's all our continents, Africa, Asia, Europe, North America, et cetera. And there's the count of rows in each of those continents.

So, in this example, the Continent column is used to group the results for the COUNT function. And the COUNT function will apply to each of those groups. And, of course, this grouping will work with any aggregate function. There's one more option that I want to show you. I'm going to use COUNT for this, and again, this works for many of the aggregate functions. I can say COUNT DISTINCT and Continent, and this will actually tell us how many distinct continents there are in this table.

And when I press Go it shows that there are seven distinct values for the continent column. So, what this does it goes through the entire table and it sorts it by continent. And then it only counts each value for continent once, it does not count the duplicates. And that's the distinct keyword inside of the parentheses as the argument for the aggregate function. And again, this works with a lot of the aggregate functions. Another common aggregate function is the GROUP CONCAT function which will concatenate a number of values in a group.

So I can say Select Group, CONCAT, Name, FROM Country. WHERE Region equals Western Europe, and press Go. And here are all the values for the name column where the region equals Western Europe. Now, instead of using this where clause, I can use a GROUP BY clause. Let's see, GROUP BY Region. And now, I get a row for each region with all of the values for name concatenated for that region.

You'll notice that the separator defaults to a common. I can change that by using the separator option, and give it a slash instead. And now, we have slashes instead of commas. I can also use distinct with this. I can say DISTINCT Continent. And I don't need this group by over here anymore. And I can say Go. And I can actually order it by continent. I can say ORDER BY Continent.

And it will change the order of this and put the a's first. So that's the GROUP CONCAT. There are also some numeric functions that are used as aggregates. We have average, and we'll use population for this. So you'll get the average population. Where region equals western Europe. And there's our average population. You can also get the minimum and maximums instead of, or in addition to the average I could say MIN and MAX.

And this will give us the minimum and maximum values for a population that satisfies that. And again, we could do this with GROUP BY instead of the WHERE clause if we wanted to. Or I can get SUMs, which will add them all up. I can even get a standard deviation with STD. And there's our sum and our standard deviation. So aggregate functions are functions that operate on a set of rows rather than row by row. MySQL has a good selection of aggregate functions for working with both strings and numerics.

There are currently no FAQs about MySQL Essential Training.

Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.

Mark all as unwatched Cancel


You have completed MySQL Essential Training.

Return to your organization's learning portal to continue training, or close this page.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.