Example of Average, Sum, Min and Max functions in MySQL

Example of Average, Sum, Min and Max functions in MySQL

Hi,

How to use the aggregate functions like Average, Sum, Min and Max in MySQL?

Thanks

View Answers

July 12, 2016 at 10:00 AM

Hi,

Check Aggregate Functions for more details.

Thanks


July 12, 2016 at 10:01 AM

Hi,

Here is few example of aggregate functions in MySQL:

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
+------------+-----------+----------------------+-------------+
3 rows in set (0.00 sec)

mysql> select avg(email_count) from email;
+------------------+
| avg(email_count) |
+------------------+
|         266.6667 |
+------------------+
1 row in set (0.03 sec)

mysql> select avg(email_count) from email where email_count>100;
+------------------+
| avg(email_count) |
+------------------+
|         350.0000 |
+------------------+
1 row in set (0.02 sec)

mysql> select count(*) from email;
+----------+
| count(*) |
+----------+
|        3 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from email where email_count>100;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> select max(email_count) from email;
+------------------+
| max(email_count) |
+------------------+
|              500 |
+------------------+
1 row in set (0.02 sec)

mysql> select max(email_count) from email where email_count<500;
+------------------+
| max(email_count) |
+------------------+
|              200 |
+------------------+
1 row in set (0.00 sec)

mysql> select max(email_count) from email;
+------------------+
| max(email_count) |
+------------------+
|              500 |
+------------------+
1 row in set (0.00 sec)

mysql> select min(email_count) from email;
+------------------+
| min(email_count) |
+------------------+
|              100 |
+------------------+
1 row in set (0.00 sec)

mysql> select sum(email_count) from email;
+------------------+
| sum(email_count) |
+------------------+
|              800 |
+------------------+
1 row in set (0.00 sec)

Thanks


July 14, 2016 at 3:16 AM

Check following video:

Thanks









Related Tutorials/Questions & Answers:
Example of Average, Sum, Min and Max functions in MySQL
Example of Average, Sum, Min and Max functions in MySQL  Hi, How to use the aggregate functions like Average, Sum, Min and Max in MySQL? Thanks..., Here is few example of aggregate functions in MySQL: mysql> select * from
hibernate criteria Max Min Average Result Example
hibernate criteria Max Min Average Result Example In this Example, We... of Projection. In this example we create a criteria instance and implement the Projections class max, min ,avg methods. Here is the simple Example code files
Advertisements
MySQL Aggregate Function
in the MySQL Query. In this example we use the aggregate function ('COUNT', 'MIN', 'MAX', and 'SUM') in the MySQL Query. The group (aggregate) functions.... Query   SELECT designation, MIN(salary) , MAX
Mysql Min Max
Mysql Min Max. To understand and grasp the example we create a table 'employee... Mysql Min Max       Mysql Min Max is useful to find the minimum and maximum records from a table
SQL Aggregate Functions List
List Queries. The Aggregate Function include the average, count, min, max, sum etc... an example from SQL Aggregate Functions List. To understand the example we create... the average sum of the records marks as fieldname marks, id and name from table 'stu
Calculate sum and Average in java
. Description:- In this example we are calculating sum and average of n numbers...Calculate sum and Average in java  How to calculate sum and average... the sum by the total number of numbers, we have determined the average of numbers
Using Min, Max and Count on HQL.
Using Min, Max and Count on HQL.  How to use Min, Max and Count on HQL
sum and average of grades
sum and average of grades  how to print a program which is sum and average of Korean (90), English(85), Mathematics(78), Biology(65), Chemistry(83
ModuleNotFoundError: No module named 'min-max'
ModuleNotFoundError: No module named 'min-max'  Hi, My Python...-max' How to remove the ModuleNotFoundError: No module named 'min-max... to install padas library. You can install min-max python with following command
ModuleNotFoundError: No module named 'min-max'
ModuleNotFoundError: No module named 'min-max'  Hi, My Python...-max' How to remove the ModuleNotFoundError: No module named 'min-max... to install padas library. You can install min-max python with following command
MySQL Average Command
MySQL Average Command This example illustrates how to execute the Average command in MySQL. In this example we create a select query to find the average of 'lastAccess' field.  ADS_TO_REPLACE_1 Query
how to calculate max and min - RUP
function max and min in java. public class MathMaxMin { public static void main(String args[]) { // Method for the max number among the pair...how to calculate max and min  hye!i'm a new for the java and i want
how to calculate max and min in the loop - Java Beginners
how to calculate max and min in the loop  thanks coz giving me... main(String a[]) throws IOException { int max,min; max=Integer.parseInt(a[0]); min=Integer.parseInt(a[0]); for(int i=0;imax) max=Integer.parseInt
Hibernate criteria average Example
Hibernate criteria average Example   How to find the average in Hibernate? Thanks   Example of finding average on a filed in Hibernate using criteria. For this you have to use Projections.avg() in your program. Check
Hibernate Min() Function (Aggregate Functions)
Hibernate Min() Function (Aggregate Functions)  ... the Min() function. Hibernate supports multiple aggregate functions. When...(...), min(...), max(...) , count(*), count(...), count(distinct ...), count(all
Hibernate Criteria Max Date Example
Hibernate Criteria Max Date Example   How to write example program... the following links: Example: Hibernate Criteria Max Date. Check the tutorial... for finding max Date in Java program then check the following links: Example
JDBC Select Max Example
JDBC Select Max Example In this tutorial we will learn how use  MAX ()  in query with mysql JDBC driver. This  tutorial  use... values   that  pass in Max function  i.e  "SELECT MAX
ModuleNotFoundError: No module named 'argparse-min-example'
ModuleNotFoundError: No module named 'argparse-min-example'  Hi...: No module named 'argparse-min-example' How to remove the ModuleNotFoundError: No module named 'argparse-min-example' error? Thanks   Hi
ModuleNotFoundError: No module named 'argparse-min-example'
ModuleNotFoundError: No module named 'argparse-min-example'  Hi...: No module named 'argparse-min-example' How to remove the ModuleNotFoundError: No module named 'argparse-min-example' error? Thanks   Hi
Hibernate Max() Function (Aggregate Functions)
(...), sum(...), min(...), max(...) , count(*), count(...), count(distinct... Hibernate Max() Function (Aggregate Functions... to use the Max() function. Hibernate supports multiple aggregate functions. When
Mysql Min Date
Mysql Min Date. To understand example we create a table 'Employee' with required... Mysql Min Date       Mysql Min Date is used to return the minimum date record from table Employee
Mysql Max Date
illustrate an example from 'Mysql Max Date'.To grasp this example we create a table... Mysql Max Date       Mysql Max Date is used to return the maximum  value of date
Mysql Max Date
from 'Mysql Max Date'.To grasp this example we create a table employee1... Mysql Max Date       Mysql Max Date is used to return the maximum  value of date from a table
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause is used to perform  various Functions like Sum, Count, Average, Maximum and Minimum. Understand
Java bigdecimal min example
Java bigdecimal min example       Example below demonstrates the working of bigdecimal class min() method. Java min method analysis the bigdecimal objects value and returns
Aggregate Functions
in the given below section. AVG COUNT MAX MIN SUMADS_TO_REPLACE_1 Here is the video tutorial of: "How to use aggregate functions in MySQL?"...Aggregate Functions      
Java bigdecimal max example
Java bigdecimal max example       Example below demonstrates the working of bigdecimall class max() method. Java max method analysis the bigdecimal objects value and returns
Max()
Max()  How to find maximum values A101,A107,A108 from a table in sql
Max()
Max()  How to find maximum values A101,A107,A108 from a table in sql
SQL Aggregate Functions Where Clause
. The Aggregate Function include Sum , Count, Max, Min and Average. Understand... Aggregate Functions Where Clause'. To understand and grasp the example we start... SQL Aggregate Functions Where Clause   
SQL Average Count
SQL Average Count       Average Count in SQL is used to count the aggregate sum of any field... illustrate an simple demonstrative example ,which helps you to calculate the average
Hibernate Criteria average example
Hibernate Criteria average example - Learn how to perform Hibernate Criteria Average Query Here we will use the avg() method.... Our example will return the average of employee salary.ADS_TO_REPLACE_1
Average
Average   I have created a file that reads in a text file for a combo box which are exams assignments and quizes. I then have a a textfield..., assignments, etc.) so I can have the average of each item. I then need to graph
Hibernate min() Function
Hibernate min() Function This section contains an example of the HQL min() function. min() function in HQL returns the smallest value from the selected... for example : min( [ distinct | all ] object.property ) Example : An example is being
Aggregate Functions in SQL, SQL Tutorial
in the given below section. AVG COUNT MAX MIN SUMADS_TO_REPLACE_1 For all of the above... Aggregate Functions      ... of which we can use many arithmetic operation like average, count, maximum
sum
sum  a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9
sum and avg function using HQL.
in HQL?   HQL supports many aggregate functions. Sum and avg are some.... avg() function returns average of specified field in the table. Example... employee employee0_ Average of salary : 68750.0 Description: This example
Mysql Date Max
Mysql Date Max      ... with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example from Mysql Date Max. To grasp this example, we create a table 'employees'. The create table
Determine Average by removing Largest and Smallest Number
into a variable 'sum' which is further used in determining the average. Here is the code...]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int j = 0...; } } System.out.println("Minimum=" + min); System.out.println("Maximun=" + max); int newArr
sum
; sum=sum+s; if(i==n){ System.out.print(s...+"+"); } System.out.print("\nSum of the series : "+sum
Order by example in MySQL
Order by example in MySQL  Hi, How to use the order by in MySQL? Thanks   Hi, The order by clause in used in MySQL for ordering the result in ascending or descending order. For example following query order the data
What is Character Functions
per row, use group functions. They are AVG, COUNT, MAX, MIN & SUM. Thanks...What is Character Functions  What is Character Functions   Hi, Here is the answer,ADS_TO_REPLACE_1 Character Functions are INITCAP, UPPER
Hibernate Criteria Aggregate Functions Example
Hibernate Criteria Aggregate Functions Example  I need Hibernate Criteria Aggregate Functions Example program with source code, I want example... and article? Thanks   Example of Hibernate Criteria Aggregate Functions
SQL Functions
the aggregate function ('COUNT', 'MIN', 'MAX', and 'SUM') in the MySQL Query... in this Tutorial illustrate an example from 'Mysql Update'.To grasp this example we... The Tutorial in this section illustrate an example from 'Mysql Now Current Date Time
Hibernate Projection Example (Sum)
Hibernate Projection Example (Sum)     ... function like: sum() using hibernate projection.  The following example to calculate the sum of invested_amount to the Insurance table ADS_TO_REPLACE_1
MySQL Addition
; MySQL Addition returns you the sum value of a specific column for a group... of 'MySQL Addition'. To understand the example we have a table employee... | +--------+--------+ In this example, the sum() function is used
Distinct and Limit example in MySQL
Distinct and Limit example in MySQL  Hi, How to use the distinct and limit with SQL query in MySQL? Thanks   Hi, Here is example...) from email where email_count >100; Here is example of limit in MySQL
php mysql fetch array example
php mysql fetch array example  How to fetch data from mysql and store it into an array in PHP? Please post an example. Thanks in Advance
Finding Average in JSP
, 78, 96}; float sum, average; sum = 0; for (int j...; } average = sum / grades.length; out.println("...Finding Average in JSP      
Example of sorting results in MySQL
Example of sorting results in MySQL  Hi, How to sort the results in MYSQL query? Thanks   Hi, You can use the order by clause in SQL statement to sort the data in ascending or descending orders. Lets consider

Ads