Home > Database > Mysql Tutorial > body text

Mean and mode in SQL Server

WBOY
Release: 2023-08-25 18:21:02
forward
1508 people have browsed it

SQL Server 中的均值和众数

Problem Statement

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

The mode of the data set is the value that appears most frequently in a series of data

If our data set is {1, 2, 3, 4}, the average value is − (1 2 3 4) / 4 = 2.5

If our data set is {1, 2, 3, 4, 1, 1, 1, 1}, the mode is − 1 because it occurs 5 times .

Example

  • First, create a table-
CREATE TABLE NUMBERS (
   value INT
)
Copy after login
  • 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);
Copy after login
  • Use the following query to find the mean -
SELECT AVG(val) FROM NUMBERS;
Copy after login
  • Insert pattern-less rows with duplicate values-
INSERT INTO NUMBERS VALUES (1);
INSERT INTO NUMBERS VALUES (1);
INSERT INTO NUMBERS VALUES (1);
INSERT INTO NUMBERS VALUES (1);
Copy after login
  • Use the following query to find the pattern -
SELECT TOP 1 val
FROM NUMBERS
GROUP BY val
ORDER BY COUNT(*) DESC
Copy after login

The above is the detailed content of Mean and mode in SQL Server. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template