Exercise 12 of 17

Regex filter and a computed column

Fixed training server

For sequences whose division matches the regular expression 'Basel.*', return the strain together with an added column 'area' set to the constant 'Basel'. Order by strain and return the first 10 rows.

The output should have this shape:

strain     | area
---------- | -----
sample-001 | Basel
sample-002 | Basel

Write a query and run it. The result is compared with the reference answer without considering row order.

Loading query editor…
Explanation

Filter the table with like to keep divisions that match 'Basel.*'. Use map to add the constant area value, project the requested columns, order the rows by strain and keep the first 10.

Reference answer
default
  .filter(division.like('Basel.*'))
  .map({area := 'Basel'})
  .project({strain, area})
  .orderBy({strain})
  .limit(10)