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 .
CREATE TABLE NUMBERS ( value INT )
INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (2); INSERT INTO NUMBERS VALUES (3); INSERT INTO NUMBERS VALUES (4);
SELECT AVG(val) FROM NUMBERS;
INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (1); INSERT INTO NUMBERS VALUES (1);
SELECT TOP 1 val FROM NUMBERS GROUP BY val ORDER BY COUNT(*) DESC
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!