The Wayback Machine - https://web.archive.org/web/20240109094923/https://www.geeksforgeeks.org/find-mean-mode-sql-server/
Open In App
Related Articles

Mean and Mode in SQL Server

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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:

Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation course.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 28 Mar, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads