Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Database
  • Getting started
    • Overview
    • Create databases
    • Examples of YQL queries
    • Examples of operations in the YDB CLI
    • Launch a test app
    • Document API
    • Developing in NodeJS through the Document API
  • Step-by-step instructions
    • Database management
    • How to connect to a database
    • Table management
    • Reading and writing data
    • Working with secondary indexes
  • Working with the SDK
  • Concepts
    • Overview
    • Data model and schema
    • Serverless and Dedicated operation modes
    • Data types
    • Transactions
    • Secondary indexes
    • Time to Live (TTL)
    • Terms and definitions
    • Quotas and limits
  • Access management
  • Pricing policy
    • Overview
    • Serverless mode
    • Dedicated mode
  • Recommendations
    • Schema design
    • Partitioning tables
    • Secondary indexes
    • Paginated output
    • Loading large data volumes
    • Using timeouts
  • YDB API and API reference
    • Database limits
    • Handling errors in the API
  • Amazon DynamoDB-compatible HTTP API
    • API reference
      • All methods
      • Actions
        • BatchGetItem
        • BatchWriteItem
        • CreateTable
        • DeleteItem
        • DeleteTable
        • DescribeTable
        • GetItem
        • ListTables
        • PutItem
        • Query
        • Scan
        • TransactGetItems
        • TransactWriteItems
        • UpdateItem
      • Common errors
  • YQL reference guide
    • Overview
    • Data types
      • Simple
      • Optional
      • Containers
      • Special
    • Syntax
      • Unsupported statements
      • For text representation of data types
      • Expressions
      • CREATE TABLE
      • DROP TABLE
      • INSERT INTO
      • UPSERT INTO
      • REPLACE INTO
      • UPDATE
      • DELETE
      • SELECT
      • GROUP BY
      • JOIN
      • FLATTEN
      • ACTION
      • DISCARD
      • PRAGMA
      • DECLARE
      • OVER, PARTITION BY, and WINDOW
    • Built-in functions
      • Basic
      • Aggregate
      • Window
      • For lists
      • For dictionaries
      • For JSON
      • For structures
      • For types
    • Preset user-defined functions
      • HyperScan
      • Pcre
      • Pire
      • Re2
      • String
      • Unicode
      • Datetime
      • Url
      • Ip
      • Digest
      • Math
      • Histogram
    • For text representation of data types
  • YQL tutorial
    • Overview
    • Creating a table
    • Adding data to a table
    • Selecting data from all columns
    • Selecting data from specific columns
    • Sorting and filtering
    • Data aggregation
    • Additional selection criteria
    • Joining tables by JOIN
    • Data insert and update by REPLACE
    • Data insert and update by UPSERT
    • Data insert by INSERT
    • Data update by UPDATE
    • Deleting data
    • Adding and deleting columns
    • Deleting a table
  • Maintenance
    • Backups
  • Diagnostics
    • System views
  • Questions and answers
    • General questions
    • Errors
    • YQL
    • All questions on the same page
  • Public materials
  1. YQL tutorial
  2. Additional selection criteria

Additional selection criteria

    Select all the episode names of the first season of each series and sort them by name.

    Note

    We assume that you already created the tables in step Creating a table and populated them with data in step Adding data to a table.

    SELECT
        series_title,               -- series_title is defined below in GROUP BY
    
        String::JoinFromList(       -- calling a C++ UDF,
                                    -- see below
    
            AGGREGATE_LIST(title),  -- an aggregate function that
                                    -- returns all the passed values as a list
    
            ", "                    -- String::JoinFromList concatenates
                                    -- items of a given list (the first argument)
                                    -- to a string using the separator (the second argument)
        ) AS episode_titles
    FROM episodes
    WHERE series_id IN (1,2)        -- IN in the WHERE clause defines the set of values
                                    -- to be included into the result.
                                    -- Syntax:
                                    -- test_expression (NOT) IN
                                    -- ( subquery | expression ` ,...n ` )
                                    -- If the value of test_expression is equal
                                    -- to any value returned by subquery or is equal to
                                    -- any expression from the comma-separated list,
                                    -- the result value is TRUE; otherwise, it's FALSE.
                                    -- using NOT IN negates the result of subquery
                                    -- or expression.
                                    -- Warning: using null values together with
                                    -- IN or NOT IN may lead to undesirable outcomes.
    AND season_id = 1
    GROUP BY
        CASE                        -- CASE evaluates a list of conditions and
                                    -- returns one of multiple possible result
                                    -- expressions. CASE can be used in any
                                    -- statement or with any clause
                                    -- that supports a given statement. For example, you can use CASE in
                                    -- statements such as SELECT, UPDATE, DELETE,
                                    -- and in clauses such as IN, WHERE, ORDER BY.
            WHEN series_id = 1
            THEN "IT Crowd"
            ELSE "Other serial"
        END AS series_title         -- GROUP BY can be performed on
                                    -- an arbitrary expression.
                                    -- Result is available in SELECT
                                    -- via the alias specified with AS.
    ;
    
    COMMIT;
    
    Language
    Careers
    Privacy policy
    Terms of use
    © 2021 Yandex.Cloud LLC