WHERE

WHERE clause allows to filter the data by specifying conditions.

Syntax

  1. SELECT *
  2. FROM table_name
  3. WHERE condition;

If there is a WHERE clause, it must contain an expression with the Boolean type. This is usually an expression with comparison and logical operators. Rows where this expression evaluates to false are excluded from further transformations or result.

Examples

Logical operators

Supports AND, OR as logical operators and can assemble conditions using brackets ().

  1. SELECT * FROM system_metrics
  2. WHERE idc = 'idc0' AND (host = 'host1' OR host = 'host2');

Numeric

Supports =, !=, >, >=, <, <= as comparison operators.

  1. SELECT * FROM system_metrics WHERE cpu_util = 20.0;
  2. SELECT * FROM system_metrics WHERE cpu_util != 20.0;
  3. SELECT * FROM system_metrics WHERE cpu_util > 20.0;
  4. SELECT * FROM system_metrics WHERE cpu_util >= 20.0;
  5. SELECT * FROM system_metrics WHERE cpu_util < 20.0;
  6. SELECT * FROM system_metrics WHERE cpu_util <= 20.0;

Evaluates match or mismatch against a list of elements.

List match

  1. SELECT * FROM system_metrics WHERE idc IN ('idc_a', 'idc_b');

List mismatch

  1. SELECT * FROM system_metrics WHERE idc NOT IN ('idc_a', 'idc_b');