Once you have selected a data source, you can use a RAQL query to analyze the data. RAQL is based on SQL and additionally equipped with functional extensions which are not defined in SQL. The subsequent documentation focuses on how to work with RAQL and with those functional extensions. For a detailed introduction to SQL we refer to the standard SQL text books.
RAQL provides the typical SQL clauses for reading and exploring data. Some SQL clauses and syntax are not found in RAQL. A RAQL query is composed of clauses:
See Language Reference for a synopsis of the valid expressions for each of these clauses.
The most basic form of a RAQL query includes the SELECT and the FROM clause.
The SELECT clause determines which columns to include in the result and can also perform analysis when it is used with either the OVER clause or the GROUP BY clause. The FROM clause determines which dataset to query, or can define a subquery to use as the source of data.
Set operation clauses allow the query to retrieve an additional dataset, using another query, and then join, combine or filter these datasets to derive a more complex dataset. The JOIN set operation, for example, matches rows in both datasets based on a condition and adds columns from both datasets to the joined row.
The WHERE clause filters rows from the dataset. ORDER BY sorts the result rows. LIMIT determines the maximum number of result rows that the query can return.
The OVER and GROUP BY clauses both group dataset rows into different sets based on an expression. These groups determine the scope of rows that are used in analytic functions in the SELECT clause. The HAVING clause filters the set of groups that are returned in a GROUP BY clause.
OVER and GROUP BY are mutually exclusive as they have different effects on the data returned by the query. The OVER clause performs calculations and adds the calculations as additional columns to each row. GROUP BY instead performs calculations and returns just the calculations for each group.
Most RAQL clauses also support the use of functions within their expressions. RAQL functions come in two varieties:
Plain functions, that perform some simple transformation to the values of a column for each row, such as UPPER to change text to upper-case.
Analytic functions, more commonly known as aggregate or window functions, perform calculations using multiple rows in a group, partition or window defined in the OVER or GROUP BY clauses.
Aggregate analytic functions use all rows in the current scope, such as SUM, while window analytic functions use specific rows, such as ROW_NUMBER. These functions include simple arithmetic as well as statistical functions or other analysis algorithms.
RAQL provides a set of function extensions (plain and analytical) as well as a way for you to define your own functions. See RAQL extensions for more information.