Tips>>SQL | |||||||||||||
MAKE FULL WEB APPLICATION WITH JUST SQL KNOWLEDGE? CLICK HERE Five Important aggregate functions are COUNT, SUM, AVG, MIN, and MAX. They are called aggregate functions because they summarize the results of a query, rather than listing all of the rows.1. COUNT (*) gives the number of rows satisfying the conditions 2. SUM () gives the total of all the rows, satisfying any conditions, of the given column, where the given column is numeric. 3. AVG () gives the average of the given column. 4. MIN () gives the smallest figure in the given column. 5. MAX () gives the largest figure in the given column.
|
|||||||||||||
1. COUNT (*)
|
|||||||||||||
The keyword COUNT can be used together to count the number of distinct
results. Syntax :-
EXAMPLE:-
This example finds the number of persons with a value in the "Age" filled in the "Persons" table:
RESULT:-
The COUNT (column) function is handy for finding columns without a value. Note that the result is one less than the number of rows in the original table because one of the persons does not have an age value stored.
|
|||||||||||||
2. SUM ()
|
|||||||||||||
The SUM function returns the total sum of a column in a given selection. NULL values are not included in the calculation. Syntax :-
EXAMPLE I :-
This example returns the sum of all ages in the "person" table:
RESULTS:-
EXAMPLE II :- This example returns the sum of ages for persons that are more than 20 years old:
RESULT:-
|
|||||||||||||
3. AVG ()
|
|||||||||||||
The AVG function returns the average value of a column in a selection. NULL values are not included in the calculation.
EXAMPLE I :- This example returns the average age of the persons in the "Persons" table:
RESULT :-
EXAMPLE II :-
RESULT:-
|
|||||||||||||
4. MIN ()
|
|||||||||||||
The MIN function returns the lowest value in a column. NULL values are not included in the calculation.
EXAMPLE:-
RESULT:-
|
|||||||||||||
5. MAX ()
|
|||||||||||||
The MAX function returns the highest value in a column. NULL values are not included in the calculation.
EXAMPLE:-
RESULT:-
|
|||||||||||||
Note: The MIN and MAX functions can also be used on text columns, to find the highest or lowest value in alphabetical order. | |||||||||||||
If you don't find what you are looking for. Please click here to submit your query, our experts will reply soon. |
Terms and Conditions / Privacy Policy / Refund Policy / Shipping Policy