L2L Analytics: SQL Starter Guide for Non-SQL Users

Last updated: November 5, 2026

You don't need to be a SQL expert to answer questions in L2L Analytics. Most charts can be built without any SQL (see L2L Analytics: Getting Started with Datasets, Charts, and Dashboards). When you need something the chart builder can't do, a few short query patterns in SQL Lab cover most needs. This article gives you those patterns and shows how to adapt them.

When to Use SQL (and When Not To)

  • Use the chart builder first. Counts, filters, grouping by area or machine, and time trends can all be done by dragging columns onto a chart. The Tag Dispatches by Area and Minor Stops by Machine by Month walkthroughs need no SQL.

  • Use SQL when you need to: look at raw rows to understand a dataset, combine conditions the chart filters can't express, or build a custom dataset that a chart will reuse.

Prerequisites & Preparation

  • SQL Lab access: SQL Lab is hidden by default. Ask your L2L Customer Success Manager (CSM) to turn it on for your user.

  • Required Role: Creating a chart from a SQL query requires the Primary Creator role or higher. See How to update Roles in L2L Analytics.

  • Schema documentation: Open the Analytics schema documentation, linked from the Support page in Dispatch. It maps each dataset to its table and describes every field. Keep it open while you write queries.

Step-by-Step: Run Your First Query

  1. Open Analytics: Log in to Dispatch and click Analytics.

  2. Open SQL Lab: From the top menu, choose SQL > SQL Lab.

  3. Pick the Table: In the left panel, select the database and schema, then search for the table you need. The schema documentation tells you which table holds the dataset you want (for example, the Dispatch dataset).

  4. Look at the Columns: Selecting the table lists its columns. Columns follow a naming pattern such as code, name, and description, and most have 100+ columns, so search instead of scrolling.

  5. Run a Query: Type a query in the editor and click Run. Start with Pattern 1 below.

Starter Query Patterns

The patterns below use placeholders in angle brackets, such as <dispatch table> or <site name column>. Replace each placeholder, including the brackets, with the real table or column name from SQL Lab or the schema documentation. Text values such as site names go in single quotes.

Pattern 1: Look at a Few Rows

Always start here. It shows you what the data actually looks like.

SELECT *
FROM <dispatch table>
LIMIT 100;

Pattern 2: Filter to Your Site and a Date Range

Analytics shows data for all sites, so add a site filter to nearly every query.

SELECT *
FROM <dispatch table>
WHERE <site name column> = 'Your Site Name'
  AND <reported timestamp column> >= '2026-10-01'
  AND <reported timestamp column> <  '2026-11-01'
LIMIT 500;

Pattern 3: Count Dispatches by Type

Answers questions like "Which dispatch types did we create most last month?"

SELECT <dispatch type code column>,
       COUNT(*) AS dispatch_count
FROM <dispatch table>
WHERE <site name column> = 'Your Site Name'
  AND <reported timestamp column> >= '2026-10-01'
GROUP BY <dispatch type code column>
ORDER BY dispatch_count DESC;

Swap the grouped column for area, line, or machine to count by location instead.

Pattern 4: Catch Every Name Variant

Sites often name the same dispatch type differently (for example, "Red Tag 1" and "TPM Red Tag"). Search by keyword instead of an exact name:

SELECT <dispatch type code column>,
       COUNT(*) AS dispatch_count
FROM <dispatch table>
WHERE <site name column> = 'Your Site Name'
  AND LOWER(<dispatch type code column>) LIKE '%tag%'
GROUP BY <dispatch type code column>
ORDER BY dispatch_count DESC;

Pattern 5: Find Open Dispatches

Dispatches that have not been completed have no completed timestamp. This is a quick way to find old dispatches that were never closed out.

SELECT <dispatch number column>,
       <machine short description column>,
       <dispatch type code column>,
       <reported timestamp column>
FROM <dispatch table>
WHERE <site name column> = 'Your Site Name'
  AND <completed timestamp column> IS NULL
ORDER BY <reported timestamp column> ASC;

Turn a Query into a Chart

  1. Run the query and confirm the results look right.

  2. Save it as a dataset from the results panel (Save > Save dataset), and give it a clear name.

  3. Open the new dataset and build your chart as usual. Use the chart's Time grain setting to roll timestamps up to days, weeks, or months instead of writing date logic in SQL.

  4. Add the chart to a dashboard. See L2L Analytics: Building a Dashboard with Filters.

Tips

  • Write the question down first. One query or chart should answer one question.

  • Always add LIMIT while exploring. Large queries are slow and may be blocked.

  • Always filter by site. Without it, results include every site.

  • Use an AI assistant. Tools like Claude, Copilot, or Gemini can write and fix SQL for you. Give the assistant your question, the table name, and the relevant part of the Analytics schema documentation, and ask it to explain the query back to you.

  • Bring it to office hours. L2L holds weekly Analytics office hours for hands-on help. Ask your CSM for the booking link.

Next Steps