SQL Analytics

SQL Analytics allows you to carry out advanced manipulation of data using a SQL query before you visualize it.

The analytics editor provides full featured SQL support and is powered by DuckDB—an in-process database management system designed for efficient analytical query processing.

Important

The beta version of SQL Analytics previously used AlaSQL. While you can still copy the tiles created using the beta version, copying an AlaSQL query may not always be possible due to compatibility reasons.

What you can do with SQL Analytics

SQL Analytics lets you transform, aggregate, and combine data before visualizing it. Common use cases include:

  • Calculate the average time difference between when a ticket is created and resolved using SQL, then visualize the Mean Time To Resolution (MTTR).
  • Query AWS CloudWatch data to find the 95th percentile response time of a microservice, and display it as a Service Level Indicator (SLI).
  • Combine entry points from different sources, such as Azure Cost data and Azure Monitor data, to analyze the potential cost savings of turning off unused virtual machines.

Where to access the analytics editor

In the tile editor, there are two ways to access the SQL Analytics editor:

  • Select SQL from the Filter | Group | Sort tab to open the SQL editor, where you can use SQL to shape and aggregate the current dataset.
  • Enable the Multiple datasets toggle at the top of the screen. This switches from the standard tile editor to the Multiple datasets editor, where you can use SQL to shape and aggregate data from multiple datasets.

    Note

    If you exit out of the SQL Analytics mode, reverting to using the default tile editor for a tile, then you lose your SQL queries and datasets, as only the first dataset is saved.

Using the SQL editor

This uses standard Structured Query Language (SQL) and is powered by DuckDB.

By default, the Query tab in the SQL section of the SQL Analytics Editor contains a query that returns everything from the first dataset. Edit this query to return and manipulate your data as needed.

Select * FROM tickets
Note

If you perform a Count aggregation on the Shaping tab for a dataset and therefore have a column named "count", you must wrap the column name in `` to reference it in SQL: `count`.

Query editor buttons

Use the following buttons to interact with the Enter your query window.

Button
Description
Execute
Click to run the query and display the result in the SQL Output section at the bottom of the page.
More
> Force refresh
Click to to re-run the query and re-request all data stream data to ensure that it's up to date.
Done
Click to save the query and close the window.
Dock
Click to expand the Enter your query window to full size to maximize editing space. This also adds your datasets tabs next to the SQL output tab at the bottom of the page.
Close
Click to close the Enter your query window and discard your changes.

IntelliSense

The SQL query editor comes packed with IntelliSense, designed to streamline query creation. Each keystroke triggers the assistant and and provides:

  • Context-aware auto-complete: The editor suggests relevant SQL syntax, table names, and column fields based on your current input, reducing the chance of errors and speeding up query writing.
  • Real-time error detection: Common mistakes such as syntax errors or missing keywords are flagged as you type, helping you correct issues early.

Querying datasets

How you reference data in your SQL query depends on where you're writing it:

  • Filter | Group | Sort > SQL: The query operates on the tile's current dataset, which is always referenced as dataset. For example:
    SELECT
        priority,
        COUNT(*) AS TicketCount
    FROM dataset
    GROUP BY priority
    ORDER BY TicketCount DESC;
  • Multiple datasets mode: Each configured dataset is exposed as a table. By default these are named dataset1, dataset2, and so on (although you can rename them to something more meaningful). For example:
    SELECT
        priority,
        COUNT(*) AS TicketCount
    FROM dataset1
    GROUP BY priority
    ORDER BY TicketCount DESC;

Both queries return the number of tickets for each priority level. The difference is the dataset name you reference.

In Filter | Group | Sort > SQL, use dataset, which represents the current dataset. In Multiple datasets mode, reference the dataset you want to query (dataset1, dataset2, etc.).

Multiple datasets mode

After enabling the Multiple datasets toggle, the tile editor view updates to facilitate the use of multiple datasets. From the left-hand pane, you can add / edit / delete each dataset you want to use, and these display below the visualization alongside the SQL output.

If you had already selected a data stream and objects in the tile editor before enabling the toggle, then it is displayed as dataset1 and the SQL > Query tab immediately opens.

Renaming datasets

Datasets can be renamed by clicking the tab of the dataset to enable editing – hit Enter to save the change, hit Escape to cancel. For example, if you are looking at Zendesk tickets you might rename dataset1 to tickets.

Note

The new name must be alphanumeric, with no spaces or punctuation. At the point of renaming, if the SQL query is unmodified, the name of the dataset is automatically updated in the SQL query.

Dataset buttons

Use the following buttons to create new, copy existing and delete data sets.

Button
Description
Add dataset
Click to create an additional dataset. The Data Stream tab displays and you can progress through data stream configuration flow as you would in the default tile editor view.
For each new dataset you add, a new tab displays with a sequential name (dataset2, dataset3 etc.) and can be configured independently as required.
Hover over a dataset > select more
> Clone
Click to create a new dataset from the properties of the one you selected.
The new dataset takes the name of the original dataset, suffixed with "Copy" (for example, ticketsCopy).
Hover over a dataset > select more
> Delete
Click to permanently remove a dataset.

Querying multiple datasets

Multiple datasets mode lets you leverage SQL to query data from more than one dataset at a time, and even combine datasets by using a JOIN, etc.

For example, the following query compares the number of new and solved tickets per day by combining data from two different datasets.

WITH created AS (
                 SELECT `count` AS NewTickets,
                 created_at_byDay AS TDay
                 FROM dataset1
                 ORDER BY TDay),

     solved AS (
                 SELECT `count` AS SolvedTickets,
                 solved_at_byDay AS TDay
                 FROM dataset2
                 ORDER BY TDay)

SELECT TDay, 
       COALESCE(NewTickets, 0) AS Created, 
       COALESCE(SolvedTickets,0) AS Solved
FROM (
      SELECT * from created
      OUTER JOIN solved on solved.TDay = created.TDay
     )
ORDER BY TDay

This builds a daily comparison of ticket creation and resolution, which you can can then visualize as separate trend lines on a line graph:

Was this article helpful?


Have more questions or facing an issue?