OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.3.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.3.1
    iconOceanBase Database
    SQL - V 4.3.1
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    STDDEV_SAMP

    Last Updated:2024-06-28 05:30:31  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples
    Example of an aggregate function
    Example of an analytic function

    folded

    share

    Purpose

    STDDEV_SAMP() returns the sample standard deviation of a set of numeric values. The sample standard deviation is the arithmetic square root of the sample variance. The difference between STDDEV() and STDDEV_SAMP() is that the STDDEV() function returns 0 for only one row of input data, whereas STDDEV_SAMP() returns NULL. You can use this function as an aggregate or analytic function.

    Note

    • When you use this function as an analytic function, use the OVER clause to define a window over the data on which the function operates. The function operates on a group of rows to return a list of values.
    • When you use this function as an aggregate function, the function operates on a set of rows and returns a single value. You do not need to add the OVER clause.

    Syntax

    STDDEV_SAMP([ALL] expr) [ OVER (analytic_clause) ]
    

    Parameters

    Parameter Description
    ALL The entire column. This parameter is optional. Default value: ALL.
    expr An expression of a numeric data type (NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE) or a data type that can be converted to a numeric data type.
    OVER You can use the OVER clause to define a window over the data on which the function operates. For more information, see Analytic functions.

    Return type

    The return type is the same as the data type of expr.

    Examples

    The table employees has been created.

    obclient> SELECT * FROM employees;
    +---------------+-----------+------------+--------+
    | DEPARTMENT_ID | LAST_NAME | HIREDATE   | SALARY |
    +---------------+-----------+------------+--------+
    |            30 | Raphaely  | 2017-07-01 |   1700 |
    |            30 | De Haan   | 2018-05-01 |  11000 |
    |            40 | Errazuriz | 2017-07-21 |   1400 |
    |            50 | Hartstein | 2019-10-05 |  14000 |
    |            50 | Raphaely  | 2017-07-22 |   1700 |
    |            50 | Weiss     | 2019-10-05 |  13500 |
    |            90 | Russell   | 2019-07-11 |  13000 |
    |            90 | Partners  | 2018-12-01 |  14000 |
    +---------------+-----------+------------+--------+
    8 rows in set
    

    Example of an aggregate function

    Calculate the standard deviation for the salary column.

    obclient> SELECT STDDEV_SAMP(salary) FROM employees;
    +-------------------------------------------+
    | STDDEV_SAMP(SALARY)                       |
    +-------------------------------------------+
    | 6026.474330580265330900400184969999384459 |
    +-------------------------------------------+
    1 row in set
    

    Example of an analytic function

    Group the data records in the table by the department_id column and sort the data records by the hiredate column in ascending order. Return the standard deviation for the salary column.

    obclient> SELECT department_id, last_name, hiredate, salary,
                     STDDEV_SAMP(salary) OVER (PARTITION BY department_id
                      ORDER BY hiredate ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS s_samp
              FROM employees;
    +---------------+-----------+------------+--------+-------------------------------------------+
    | DEPARTMENT_ID | LAST_NAME | HIREDATE   | SALARY | S_SAMP                                    |
    +---------------+-----------+------------+--------+-------------------------------------------+
    |            30 | Raphaely  | 2017-07-01 |   1700 |                                      NULL |
    |            30 | De Haan   | 2018-05-01 |  11000 | 6576.093065034891976927852567575096065349 |
    |            40 | Errazuriz | 2017-07-21 |   1400 |                                      NULL |
    |            50 | Raphaely  | 2017-07-22 |   1700 |                                      NULL |
    |            50 | Hartstein | 2019-10-05 |  14000 | 8697.413408594534550130385653889643183203 |
    |            50 | Weiss     | 2019-10-05 |  13500 | 6961.561127601576503543602300090640831831 |
    |            90 | Partners  | 2018-12-01 |  14000 |                                      NULL |
    |            90 | Russell   | 2019-07-11 |  13000 |  707.106781186547524400844362104849039285 |
    +---------------+-----------+------------+--------+-------------------------------------------+
    8 rows in set
    

    Previous topic

    STDDEV_POP
    Last

    Next topic

    SUM
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples
    Example of an aggregate function
    Example of an analytic function