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 tables in step Creating a table and populated them with data in step Adding data to a table.

  1. SELECT
  2. series_title, -- series_title is defined below in GROUP BY
  3. String::JoinFromList( -- calling a C++ UDF,
  4. -- see below
  5. AGGREGATE_LIST(title), -- an aggregate function that
  6. -- returns all the passed values as a list
  7. ", " -- String::JoinFromList concatenates
  8. -- items of a given list (the first argument)
  9. -- to a string using the separator (the second argument)
  10. ) AS episode_titles
  11. FROM episodes
  12. WHERE series_id IN (1,2) -- IN defines the set of values in the WHERE clause,
  13. -- to be included into the result.
  14. -- Syntax:
  15. -- test_expression (NOT) IN
  16. -- ( subquery | expression ` ,...n ` )
  17. -- If the value of test_expression is equal
  18. -- to any value returned by subquery or is equal to
  19. -- any expression from the comma-separated list,
  20. -- the result value is TRUE. Otherwise, it's FALSE.
  21. -- using NOT IN negates the result of subquery
  22. -- or expression.
  23. -- Warning: using null values together with
  24. -- IN or NOT IN may lead to undesirable outcomes.
  25. AND season_id = 1
  26. GROUP BY
  27. CASE -- CASE evaluates a list of conditions and
  28. -- returns one of multiple possible resulting
  29. -- expressions. CASE can be used in any
  30. -- statement or with any clause
  31. -- that supports a given statement. For example, you can use CASE in
  32. -- statements such as SELECT, UPDATE, and DELETE,
  33. -- and in clauses such as IN, WHERE, and ORDER BY.
  34. WHEN series_id = 1
  35. THEN "IT Crowd"
  36. ELSE "Other series"
  37. END AS series_title -- GROUP BY can be performed on
  38. -- an arbitrary expression.
  39. -- The result is available in a SELECT
  40. -- via the alias specified with AS.
  41. ;
  42. COMMIT;

Additional selection criteria - 图1