- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Mean and Mode in SQL Server
Problem statement
Mean is the average of the given data set calculated by dividing the total sum by the number of values in the data set.
Mode of a data set is the value that appears most frequently in a series of data
If our dataset is {1, 2, 3, 4} then mean value is − (1 + 2 + 3 + 4) / 4 = 2.5
If our dataset is {1, 2, 3, 4, 1, 1, 1, 1} then mode value is − 1 as it appears 5 times.
Example
- First, create a table −
CREATE TABLE NUMBERS ( value INT )
- Insert data into the table −
INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (2); INSERT INTO NUMBERS VALUES (3); INSERT INTO NUMBERS VALUES (4);
- Find Mean using below query −
SELECT AVG(val) FROM NUMBERS;
- Insert few-mode rows with duplicate values −
INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (1);
- Find Mode using below query −
SELECT TOP 1 val FROM NUMBERS GROUP BY val ORDER BY COUNT(*) DESC
- Related Articles
- Difference between MySQL and SQL Server
- Difference between Oracle and SQL Server
- Difference between ETL and ELT in SQL Server
- Difference between Star schema and Snowflake schema in SQL Server
- Database Wars: MSSQL Server, Oracle PL/SQL and MySQL
- Difference between clustered index and non-clustered index in SQL server
- Equivalent of SQL Server IDENTITY Column in MySQL?
- MySQL LIMIT clause equivalent for SQL SERVER?
- How to write a MySQL “LIMIT” in SQL Server?
- The equivalent of SQL Server function SCOPE_IDENTITY() in MySQL?
- Generate table DDL via a query on MySQL and SQL Server?
- Application of Mean, Median, and Mode of Grouped Data in Psychology
- What do you mean by Mode?
- Data Replication from SAP PO to SQL Server
- What is the use of IGNORE_SPACE SQL mode?

Advertisements