Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Query
    • Overview
    • Selecting data from all columns
    • Selecting data from specific columns
    • Sorting and filtering
    • Aggregating data
    • Additional selection criteria
    • Working with JSON
    • Running a streaming data query
  • Access management
  • Pricing policy
  • Integration
  • Audit Trails events
  • FAQ
  1. Working with YQL
  2. Additional selection criteria

Adding other aggregation criteria

Written by
Yandex Cloud
Improved by
Max Z.
Updated at March 6, 2025

You can aggregate data by both column values and expressions.

For example:

  • Group taxi rides by long distance.
  • Group taxi rides by short distance.
  • Calculate the total number of grouped rides.
SELECT
    distance_type,
    COUNT(*)
FROM
    `tutorial-analytics`
GROUP BY                                -- CASE checks a list of conditions
    CASE                                -- and returns one of several possible
        WHEN trip_distance > 10         -- expressions or an expression with any operator
        THEN "long"                     -- that supports the expression in question. For example, you can use CASE
        ELSE "short"                    -- in SELECT expressions
    END AS distance_type                -- and with operators IN, WHERE, and ORDER BY.
                                        -- You can run GROUP BY
                                        -- for any expression.
                                        -- The result is available in SELECT
                                        -- via an alias specified using AS.

View the example in the right-hand section and click Run.
Query results are available in the Result tab as a table or schema.

See alsoSee also

  • SELECT
  • GROUP BY
  • CASE

Was the article helpful?

Previous
Aggregating data
Next
Working with JSON
© 2025 Direct Cursus Technology L.L.C.