Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Period-over-Period Functions

Updated on 2025-01-24 GMT+08:00

This section describes the basic syntax and examples of period-over-period functions.

compare Function

This function is used to compare the calculation result in the current period with that in a previous period (n seconds ago).

Syntax

  • This syntax is used to compare the calculation result in the current period with that n seconds ago.
    compare(x,n)
  • This syntax is used to compare the calculation result in the current period with that n1, n2, and n3 seconds ago.
    compare(x, n1, n2, n3...)

Description

Table 1 Parameters of the year-on-year function

Parameter

Description

x

Name of the target column. The value is of the double or long type.

n

Time window (in seconds). For example, 3600 means 1 hour, 86400 means 1 day, 604800 means 1 week, and 31622400 means 1 year.

Returned Data Type

JSON array. The format is [Current calculation result,Calculation result n seconds ago,Ratio of the current calculation result to that n seconds ago].

Example

This example calculates the ratio of the number of visits in the same period of the current hour to that in the same period of the previous day.

  1. Set the query and analysis time range to 1 hour (full hour), and run the following query and analysis statements: In the preceding command, 86400 indicates the current time minus 86400 seconds (one day).
    SELECT
    compare(PV, 86400)
    FROM  (SELECT count(*) AS PV )
  2. Query and analysis results.
    Figure 1 Query and analysis results
    NOTE:
    • 5994.0 indicates the number of website visits in the current hour (for example, from 2021-01-02 00:00:00 to 2021-01-02 01:00:00).
    • 6000.0 indicates the number of website visits in the same period of the previous day, for example, from 2021-01-01 00:00:00 to 2021-01-01 01:00:00.
    • 0.999 indicates the ratio of the number of website visits in the current hour to that in the same period of the previous day.
  3. Query and analysis results displayed in columns.
    SELECT
    diff[1] as "today",
    diff[2] as "yesterday",
    diff[3] as "ratio"
    FROM(SELECT compare(pv, 86400) AS diff FROM (SELECT count(*) AS pv ))
    Figure 2 Query and analysis results

ts_compare Function

This function is used to compare the calculation result in the current period with that n seconds ago.

NOTE:

The ts_compare function must be grouped by time column (GROUP BY).

Syntax

  • This function is used to compare the calculation result in the current period with that n seconds ago.
    ts_compare(x, n)
  • This function is used to compare the calculation result in the current period with that n1, n2, and n3 seconds ago.
    ts_compare(x, n1, n2, n3...)

Description

Table 2 Parameters of the period-over-period function

Parameter

Description

x

The value is of the double or long type.

n

Time window (in seconds). For example, 3600 (1 hour), 86400 (1 day), 604800 (1 week), and 31622400 (1 year).

Returned Data Type

JSON array. The format is [Current calculation result,Calculation result n seconds ago,Ratio of the current calculation result to that n seconds ago,UNIX timestamp n seconds ago].

Example

This example compares the number of website visits in the 3 hours of today with that in the 3 hours of the previous day.

Set the query and analysis time range to 3 hours of the current day and run the following statements: In the preceding command, 86400 indicates that the current time minus 86400 seconds (one day), and date_trunc('hour',__time) indicates that the date_trunc function is used to truncate the input timestamp to the hour.

  • Query and analysis statements
    SELECT
      t_time,
      ts_compare(PV, 86400) AS data
    FROM(
        SELECT
          date_trunc('hour', __time) AS t_time,
          count(*) AS PV
        GROUP BY
          t_time
        ORDER BY
          t_time
      )
    GROUP BY
      t_time
  • Query and analysis results

    t_time

    data

    2021-10-26T06:00:00.000Z

    [159.0,224.0,0.7098214285714286,1.6351416E9]

    2021-10-26T07:00:00.000Z

    [100.0,148.0,0.6756756756756757,1.6351452E9]

    2021-10-26T08:00:00.000Z

    [100.0,100.0,1.0, 1.6016544E9, 1.6351488E9]

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback