OceanBase logo

OceanBase

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

Product Overview
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

OceanBase

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

Product Overview
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 - V2.2.77Enterprise Edition

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    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. V2.2.77
    iconOceanBase Database
    SQL - V 2.2.77Enterprise Edition
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • 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

    WINDOW FUNCTION

    Last Updated:2023-08-18 09:26:34  Updated
    Share
    What is on this page
    Share

    The WINDOW FUNCTION operator implements SQL analytic functions, or window functions, to calculate the results of relevant rows in a window.

    Window functions differ from aggregate functions in that, the latter returns only one row from a group of data, while window functions return multiple rows from a group. Each row in the group is the result of a window-based logical calculation. Therefore, in the execution of an SQL statement that includes a WINDOW FUNCTION, whose format is generally OVER(...), a WINDOW FUNCTION operator is assigned while generating the execution plan.

    Example: An execution plan that includes a WINDOW FUNCTION operator

    obclient>CREATE TABLE t1(c1 INT, c2 INT);
    Query OK, 0 rows affected (0.12 sec)
    
    obclient>INSERT INTO t1 VALUES(1, 1);
    Query OK, 1 rows affected (0.12 sec)
    
    obclient>INSERT INTO t1 VALUES(2, 2);
    Query OK, 1 rows affected (0.12 sec)
    
    obclient>INSERT INTO t1 VALUES(3, 3);
    Query OK, 1 rows affected (0.12 sec)
    
    Q1: 
    obclient>EXPLAIN SELECT MAX(c1) OVER(PARTITION BY c1 ORDER BY c2) FROM t1\G;
    *************************** 1. row ***************************
    Query Plan:
    | ========================================
    |ID|OPERATOR       |NAME|EST. ROWS|COST|
    ----------------------------------------
    |0 |WINDOW FUNCTION|    |3        |45  |
    |1 | SORT          |    |3        |44  |
    |2 |  TABLE SCAN   |T1  |3        |37  |
    ========================================
    
    Outputs & filters: 
    -------------------------------------
      0 - output([T_FUN_MAX(T1.C1)]), filter(nil), 
          win_expr(T_FUN_MAX(T1.C1)), partition_by([T1.C1]), order_by([T1.C2, ASC]), window_type(RANGE), upper(UNBOUNDED PRECEDING), lower(CURRENT ROW)
      1 - output([T1.C1], [T1.C2]), filter(nil), sort_keys([T1.C1, ASC], [T1.C2, ASC])
      2 - output([T1.C1], [T1.C2]), filter(nil), 
          access([T1.C1], [T1.C2]), partitions(p0)
    

    When an ORDER BY or PARTITION BY is specified in a window function, a SORT operator is assigned at the subsequent layer to return the sorting result to the WINDOW FUNCTION operator.

    In the preceding example, the Outputs & filters section in the execution plan display of query Q1 shows in detail the output information of the WINDOW FUNCTION operator.

    Field
    Description
    output The output expression of the operator.
    filter The filter conditions of the operator. In this example, the condition is set to nil because no filter is configured for the WINDOW FUNCTION operator.
    win_expr Indicates the aggregate function to be used in the window. For example, query Q1 obtains the maximum value of column c1, so the function is T_FUN_MAX(t1.c1).
    partition_by Indicates how groups are partitioned in the window. For example, query Q1 is partitioned by column c1, so the value is t1.c1.
    order_by Indicates how rows are ordered in the window. For example, query Q1 requires ordering by column c2, so the value is t1.c2.
    window_type The type of the window, which could be either "range" or "rows": * range: In the default "range" mode, the upper and lower boundaries of the window are calculated based on logical offsets. * rows: In the "rows" mode, the upper and lower boundaries of the window are calculated based on physical offsets. For example, the default "range" mode is selected in query Q1 as no window type is specified.
    upper Sets the upper boundary of the window: * UNBOUNDED: No boundary is specified and the maximum value is used (default). * CURRENT ROW: Starts from the current row. A numeric value indicates the number of rows to move from the current. * PRECEDING: sets the boundary in the preceding rows. * FOLLOWING: sets the boundary in the following rows. For example, the upper boundary in query Q1 is set to unbounded preceding.
    lower Sets the lower boundary of the window. The attribute settings are the same as those of the upper boundary. For example, the lower boundary in query Q1 is set to the current row.

    Previous topic

    GROUP BY
    Last

    Next topic

    SUBPLAN FILTER
    Next