Answer to Question #194422 in Databases | SQL | Oracle | MS Access for oliver

Question #194422

What is SQL Aggregate Functions Define with Examples


1
Expert's answer
2021-05-18T02:56:58-0400

// some corrections

Aggregate functions calculate some scalar values ​​in a rowset.

MySQL has the following aggregate functions:

AVG: calculates the average


SUM: calculates the sum of values


MIN: calculates the smallest value


MAX: calculates the largest value


COUNT: calculates the number of rows in a query


For example, we can illustrate this on the table SouthAmericanParrots,

calculating the average number of the parrots species in different countries,

finding minimal and maximal number, total count of species and countries.

create table SouthAmericanParrots(id integer, country_name varchar(50),

number_of_species integer, most_common_species varchar(100));

insert into SouthAmericanParrots(id, country_name, 

number_of_species, most_common_species) 

values(1, "Brasilia", 78, "Ara macao"),

(2, "Peru", 38, "Golden-plumed parakeet"),

(3, "Argentina", 52, "Burrowing parrot"),

(4, "Equador", 43, "Amazon");

select * from SouthAmericanParrots;

SELECT AVG(number_of_species) AS Average_number_of_species FROM SouthAmericanParrots;

SELECT MIN(number_of_species) AS Minimal_number_of_species FROM SouthAmericanParrots;

SELECT MAX(number_of_species) AS Maximal_number_of_species FROM SouthAmericanParrots;

SELECT SUM(number_of_species) AS Total_number_of_species FROM SouthAmericanParrots;

SELECT COUNT(country_name) AS Total_number_of_countries FROM SouthAmericanParrots;




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS