Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Query
    • Overview
    • Selecting all columns
    • Selecting specific columns
    • Sorting and filtering
    • Data aggregation
    • Additional filter conditions
    • Working with JSON
    • Querying streaming data
  • Access management
  • Pricing policy
  • Integrations
  • Audit Trails events
  • FAQ
  1. Working with YQL
  2. Additional filter conditions

Adding other aggregation conditions

Written by
Yandex Cloud
Improved by
Max Z.
Updated at July 7, 2026
View in Markdown

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 sum of grouped rides.
SELECT
    distance_type,
    COUNT(*)
FROM
    `tutorial-analytics`
GROUP BY                                -- CASE checks the list of conditions
    CASE                                -- and returns one of possible
        WHEN trip_distance > 10         -- expressions with any operator
        THEN "long"                     -- that supports this expression. For example, you can use CASE
        ELSE "short"                    -- in SELECT statements,
    END AS distance_type                -- inside an IN operator, and in WHERE, and ORDER BY clauses.
                                        -- You can use GROUP BY
                                        -- for any expression.
                                        -- The result will be available in the SELECT statement
                                        -- under the alias specified with the AS operator.

Check the example in the right-hand section and click Run.
The query result will appear in the Result tab as a table or chart.

Useful linksUseful links

  • SELECT
  • GROUP BY
  • CASE

Was the article helpful?

Previous
Data aggregation
Next
Working with JSON
© 2026 Direct Cursus Technology L.L.C.