Filters
You have the option to filter the records included in the query to identify a subset of records by using the WHERE clause.
This could be specify a particular age group, for example, or to only include results from a certain location.
The table below shows the operators available to apply filters:
Operator |
Explanation |
> |
Greater than |
>= |
Greater than or equal to |
< |
Less than |
<= |
Less than or equal to |
= |
Equal |
!= |
Not equal |
BETWEEN |
Select values within a given range |
IN |
Specify multiple values |
Any of these operators can be used for numeric data, but only equal and not equal can be used for categoric data.
Using the greater than symbol as an example, you could write something like this:
WHERE Category > Integer
So this part of the query would look something like this:
WHERE Income > 20000
To put it all together:
SELECT COUNT()
FROM
(A Union B) Exclude C
WHERE
Income > 20000
You can also apply filters to activation queries. This example returns a list of Twitter handles, but only if they are aged over 25.
SELECT
mydataset.TwitterHandle
FROM mydataset INTERSECT theirdataset
WHERE Age/"Years Old" < 25
Note: If you're used to writing queries in SQL, note that you don't need to use the JOIN keyword in IQL. InfoSum automatically performs the join between multiple datasets when they are referenced in a single query.
Using multiple filters
You can apply as many filters as you like to your datasets by using the AND, OR and NOT operators.
To do so, write something like this:
WHERE Category > Integer AND Category = String
So this part of the query would look something like this:
WHERE Income >= 20000 AND Age < 30
To put it all together:
SELECT COUNT()
FROM
(A Union B) Exclude C
WHERE
Income >= 20000 AND
Age < 30
Using BETWEEN and IN
You will need to include begin and end values when using the BETWEEN operator. Using BETWEEN, you could write something like this:
SELECT COUNT()
FROM A
WHERE A.Age BETWEEN 20 AND 50
The IN operator is shorthand for multiple OR conditions. Using IN, you could write something like this:
SELECT COUNT()
FROM A
WHERE A.Gender/"Binary and Other" IN ('Female','Other')
Next steps
There are two additional optional clauses available:
- the ENRICH WITH clause, which includes categories from other datasets
- the LINK WITH clause, which uses glue datasets to link keys