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.1.0

    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.1.0
    iconOceanBase Database
    SQL - V 4.1.0
    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

    PERCENTILE_CONT

    Last Updated:2023-08-01 06:02:28  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

    PERCENTILE_CONT() is an inverse distribution function that assumes a continuous distribution model. It returns an interpolated value that falls into the specified percentile value with respect to the sort specification. Nulls are ignored in the calculation.

    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

    PERCENTILE_CONT(percentile) WITHIN GROUP (ORDER BY expr [ DESC | ASC ])
    [ OVER (query_partition_clause) ]
    

    Parameters

    Parameter Description
    percentile The percentile value. It is a constant of the numeric data type in the range of [0, 1].
    Note The MEDIAN function is a special case where percentile equals 0.5.
    expr The sorting specification. The data type is numeric or datetime.
    Notice expr must be a single expression involving column references. Multiple expressions are not allowed.
    DESC | ASC Optional. The sorting method of the list.
    • ASC specifies to sort in ascending order. It is the default value.
    • DESC specifies to sort in descending order.
    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.

    Note

    This function sorts the data according to the sorting specification, and then calculates the row number based on the given percentile (P) and non-empty rows (N). The formula for calculating the row number is RN = (1+ (P*(N-1)). The final result of this function is calculated upon linear interpolation on row values between the row number CRN = CEILING(RN) and the row number FRN = FLOOR(RN). The final result is determined based on the following rules:

    If (CRN = FRN = RN), the result is (value of expression from row at RN). Otherwise, the result is:

    (CRN - RN) * (value of expression for row at FRN) + (RN - FRN) * (value of expression for row at CRN)

    Return type

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

    Examples

    Assume that you have created the table tbl1.

    obclient> SELECT * FROM tbl1;
    +------+------+------+------+
    | COL1 | COL2 | COL3 | COL4 |
    +------+------+------+------+
    |    1 | A1   |    8 |   12 |
    |    1 | A2   |   10 |   15 |
    |    1 | A3   |   11 |   16 |
    |    2 | B1   |    9 |   14 |
    |    2 | B2   |   10 |   15 |
    |    2 | B3   |    8 |   13 |
    |    2 | B4   |   11 |   16 |
    |    3 | C1   |    8 |   18 |
    |    3 | C2   |    9 |   16 |
    |    3 | C3   |   10 |   15 |
    |    3 | C4   |   11 |   12 |
    |    3 | C5   |   12 |   10 |
    +------+------+------+------+
    12 rows in set
    

    Example of an aggregate function

    Calculate the value at the 10th percentile in the col4 column.

    obclient> SELECT PERCENTILE_CONT(0.1) WITHIN GROUP (ORDER BY col4) FROM tbl1;
    +----------------------------------------------+
    | PERCENTILE_CONT(0.1)WITHINGROUP(ORDERBYCOL4) |
    +----------------------------------------------+
    |                                           12 |
    +----------------------------------------------+
    1 row in set
    

    Example of an analytic function

    Group data by the col1 column. Calculate the value at the 50th percentile in the col4 column, namely the median of the col4 column.

    obclient> SELECT col1,col4,PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY col4) OVER (PARTITION BY col1)
              FROM tbl1;
    +------+------+-------------------------------------------------------------------+
    | COL1 | COL4 | PERCENTILE_CONT(0.5)WITHINGROUP(ORDERBYCOL4)OVER(PARTITIONBYCOL1) |
    +------+------+-------------------------------------------------------------------+
    |    1 |   12 |                                                                15 |
    |    1 |   15 |                                                                15 |
    |    1 |   16 |                                                                15 |
    |    2 |   14 |                                                              14.5 |
    |    2 |   15 |                                                              14.5 |
    |    2 |   13 |                                                              14.5 |
    |    2 |   16 |                                                              14.5 |
    |    3 |   18 |                                                                15 |
    |    3 |   16 |                                                                15 |
    |    3 |   15 |                                                                15 |
    |    3 |   12 |                                                                15 |
    |    3 |   10 |                                                                15 |
    +------+------+-------------------------------------------------------------------+
    12 rows in set
    

    Previous topic

    PERCENT_RANK
    Last

    Next topic

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