RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

  • StreamSQL

    • Overview
    • Quick Start
    • Core Concepts
    • SQL Reference
    • API Reference
    • RuleGo Integration
    • functions

      • Aggregate Functions
      • Analytical Functions
        • LAG - Lag Function
        • LATEST - Latest Value Function
        • CHANGED_COL - Changed Column Function
        • HAD_CHANGED - Change Detection Function
        • 📚 Related Documentation
      • Window Functions
      • Math Functions
      • String Functions
      • Conversion Functions
      • DateTime Functions
      • JSON Functions
      • Hash Functions
      • Array Functions
      • Type Check Functions
      • Conditional Functions
      • Multi-row Functions
      • Expression Functions
      • Custom Functions
    • case-studies

目录

Analytical Functions

# StreamSQL Analytical Functions

Analytical functions are used for complex analytical calculations in data streams, supporting state management and historical data access.

# LAG - Lag Function

Syntax: lag(col, offset, default_value)
Description: Returns the value from the Nth row before the current row. offset specifies the offset amount, default_value is the default value.
Incremental Calculation: ✅ Supported
Example:

SELECT device, temperature, lag(temperature, 1) as prev_temp 
FROM stream 
GROUP BY device, TumblingWindow('10s')
1
2
3

# LATEST - Latest Value Function

Syntax: latest(col)
Description: Returns the latest value for the specified column.
Incremental Calculation: ✅ Supported
Example:

SELECT device, latest(temperature) as current_temp 
FROM stream 
GROUP BY device, TumblingWindow('10s')
1
2
3

# CHANGED_COL - Changed Column Function

Syntax: changed_col(row_data)
Description: Returns an array of column names that have changed.
Incremental Calculation: ✅ Supported
Example:

SELECT device, changed_col(*) as changed_columns 
FROM stream 
GROUP BY device, TumblingWindow('10s')
1
2
3

# HAD_CHANGED - Change Detection Function

Syntax: had_changed(col)
Description: Determines whether the value of the specified column has changed, returning a boolean value.
Incremental Calculation: ✅ Supported
Example:

SELECT device, had_changed(status) as status_changed 
FROM stream 
GROUP BY device, TumblingWindow('10s')
1
2
3

# 📚 Related Documentation

  • Aggregate Functions - Learn detailed usage of aggregate functions
  • Window Functions - Learn detailed usage of window functions
  • SQL Reference - View complete SQL syntax reference
Edit this page on GitHub (opens new window)
Last Updated: 2025/08/05, 02:24:31
Aggregate Functions
Window Functions

← Aggregate Functions Window Functions→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式