Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

MySQL VAR_SAMP Function

by suresh

MySQL VAR_SAMP Aggregate Function is useful to calculate the Sample Variance of total records (or rows) selected by the SELECT Statement.

MySQL VAR_SAMP Formula

The mathematical formula behind the VAR_SAMP to calculate the sample variance is

--Calculating Mean or Average
Mean = Sum of each individual / Total number of items

--Calculating the Sample Variance
Sample Variance = ( (OriginalValue – Mean)² + (OriginalValue – Mean)² +.... ) / (Total number of items - 1)

The syntax behind the VAR_SAMP function in MySQL is

-- VAR_SAMP in MySQL Syntax
SELECT VAR_SAMP(Column_Name)
FROM Source;

How to write VAR_SAMP function to calculate the sample Variance with an example using the below-shown data?.

MySQL VAR_SAMP Example 1

MySQL VAR_SAMP Example

The VAR_SAMP function returns the Simple Variance of total records present in a specified column. For example, the below query calculates the Sample Variance of all the records present in Yearly_Income from Customer details table.

-- MySQL VAR_SAMP example
SELECT VAR_SAMP(Yearly_Income) AS `Simple income Variance`
FROM customerdetails;
MySQL VAR_SAMP Function Example 1

MySQL VAR_SAMP Group By Example

In general, the VAR_SAMP function calculates the Sample Variance of products belongs to a particular category or color, etc. In this situation, you can use the GROUP BY Clause in the MySQL to group the products by category. And next, use VAR_SAMP Aggregate Function to calculate the Sample Variance.

-- MySQL VAR_SAMP Function Example
USE company;
SELECT  Profession,
        VAR_SAMP(Yearly_Income)
FROM customerdetails
GROUP BY Profession;

The above VAR_SAMP SELECT Statement query group the Customers by their Profession, and calculates their Sample Variance

MySQL VAR_SAMP Function Example 2

We are taking the Software Developer profession, and show you the VAR_SAMP output.

— Calculating Mean
Mean = (70000 + 79,000) / 2
Mean = 74,500

Here, we are calculating Sample Variance.
Variance = (70,000 – 74,500)² + (79,000 – 74,500)² / (2-1)
Variance = 40,500,000

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy