Mean and Mode in SQL Server

Mean is the average of the given data set calculated by dividing the total sum by the number of values in data set.

Example:

Input:  1, 2, 3, 4, 5 
Output: 3
Explanation: 
sum = 1 + 2 + 3 + 4 + 5 = 15
number of values = 5
mean = 15 / 5 = 3

Query to find mean in the table



SELECT Avg(Column_Name) 
FROM  Table_Name

Example:

Creating Table:

Table Content:

Query to find Mean:

Mode of a data set is the value that appears most frequently in a series of data.

Example:

Input:  1, 2, 2, 3, 4, 4, 4, 5, 5, 6
Output: 4
Explanation:
2 occurs 2 times, 5 occurs 2 times
4 occurs 3 times and rest other 
occurs 1 time
So, 4 occurs most frequently and 
is thus the output.

Query to find mode in the table

SELECT TOP 1 Column_Name
FROM   Table_name
GROUP  BY [Column_Name]
ORDER  BY COUNT(*) DESC

Example:

Creating Table:

Table Content:

Query to find Mode:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.