Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
SQL Count, Sum, Avg | SQL Aggregate Functions
SQL Tutorial for Beginners
course content

Contenido del Curso

SQL Tutorial for Beginners

SQL Tutorial for Beginners

1. Database & Introduction to Syntax
2. SQL Aggregate Functions
3. Filtering Statements

SQL Count, Sum, Avg

Similar to the previous chapter, SUM, AVG, and COUNT functions are aggregate functions that return the sum of field, average value, and count. SUM and AVG can be applied only for numbers, and COUNT - for fields of any data type.

1
SELECT AVG(price) FROM songs
copy

If you want to find the number of records with some condition, you can apply COUNT to the *.

This query outputs the number of records with the release date in the 20th century:

12
SELECT COUNT(*) FROM songs WHERE year <= 2000
copy

Aggregate functions and Distinct

If you want to apply aggregate function to the unique values, write DISTINCT inside this function and before the column name:

1
SELECT COUNT(DISTINCT song) FROM songs
copy

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 2. Capítulo 3
toggle bottom row

SQL Count, Sum, Avg

Similar to the previous chapter, SUM, AVG, and COUNT functions are aggregate functions that return the sum of field, average value, and count. SUM and AVG can be applied only for numbers, and COUNT - for fields of any data type.

1
SELECT AVG(price) FROM songs
copy

If you want to find the number of records with some condition, you can apply COUNT to the *.

This query outputs the number of records with the release date in the 20th century:

12
SELECT COUNT(*) FROM songs WHERE year <= 2000
copy

Aggregate functions and Distinct

If you want to apply aggregate function to the unique values, write DISTINCT inside this function and before the column name:

1
SELECT COUNT(DISTINCT song) FROM songs
copy

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 2. Capítulo 3
toggle bottom row

SQL Count, Sum, Avg

Similar to the previous chapter, SUM, AVG, and COUNT functions are aggregate functions that return the sum of field, average value, and count. SUM and AVG can be applied only for numbers, and COUNT - for fields of any data type.

1
SELECT AVG(price) FROM songs
copy

If you want to find the number of records with some condition, you can apply COUNT to the *.

This query outputs the number of records with the release date in the 20th century:

12
SELECT COUNT(*) FROM songs WHERE year <= 2000
copy

Aggregate functions and Distinct

If you want to apply aggregate function to the unique values, write DISTINCT inside this function and before the column name:

1
SELECT COUNT(DISTINCT song) FROM songs
copy

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Similar to the previous chapter, SUM, AVG, and COUNT functions are aggregate functions that return the sum of field, average value, and count. SUM and AVG can be applied only for numbers, and COUNT - for fields of any data type.

1
SELECT AVG(price) FROM songs
copy

If you want to find the number of records with some condition, you can apply COUNT to the *.

This query outputs the number of records with the release date in the 20th century:

12
SELECT COUNT(*) FROM songs WHERE year <= 2000
copy

Aggregate functions and Distinct

If you want to apply aggregate function to the unique values, write DISTINCT inside this function and before the column name:

1
SELECT COUNT(DISTINCT song) FROM songs
copy

Tarea

Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 2. Capítulo 3
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt