All Products
Search
Document Center

Simple Log Service:HAVING clause

Last Updated:Jun 20, 2026

The HAVING clause filters grouped results or aggregation results.

Syntax

HAVING bool_expression
Important
  • The HAVING clause filters aggregation results, whereas the WHERE clause filters raw data before aggregation.

  • The HAVING clause is evaluated after the GROUP BY clause and before the ORDER BY clause.

Parameters

Parameter

Description

bool_expression

A Boolean expression.

Examples

  • Example 1: Return the request URIs with an average request duration greater than 40 seconds.

    • Query statement

      * |
      SELECT
        avg(request_time) AS avg_time,
        request_uri
      GROUP BY
        request_uri
      HAVING
        avg(request_time) > 40
    • Query and analysis result: The result lists the avg_time and request_uri for URIs where the average request duration is greater than 40 seconds.

  • Example 2: Query service logs to find Projects with a write latency greater than 1,000 microseconds.

    • Query statement

      * |
      SELECT
        avg(latency) AS avg_latency,
        Project
      GROUP BY
        Project
      HAVING
        avg_latency > 1000
    • Query and analysis result: The query returns one row, showing an avg_latency of 1569.909090909091 for the corresponding Project name, which confirms that the average latency is greater than 1,000.