Examples

Real-world SemQL queries from simple to complex

A library of SemQL queries covering common analytical scenarios. Start with the simple ones to get a feel for the syntax, then work your way to the advanced patterns.


Simple queries

List all records from a model

SELECT name, email FROM customers

Filter with a predefined filter

SELECT name, email
FROM customers[enterprise]

Filter with a WHERE clause

SELECT name, region, created_at
FROM customers
WHERE region = 'Europe'
ORDER BY created_at DESC

Use a measure (no aggregation in the query needed)

SELECT name, total_revenue
FROM customers
GROUP BY name
ORDER BY total_revenue DESC
LIMIT 10

Filtering and aggregation

Revenue by region, for a specific year

Top products by order count, last 30 days

Active organizations with more than 5 users

Monthly revenue trend


Joins

Organizations with their user counts

Orders with customer details

Revenue per account manager (three-way join)


Window functions

Rank customers by revenue within each region

Month-over-month revenue change

Running total of revenue


CTEs

Two-step analysis: find top regions, then show their details

Cohort comparison using CTEs


UNION

Compare two time periods side by side

Combine two segments into a single report


Geo functions

Stores within 50 km of a city, sorted by distance

Customers grouped by proximity band


Putting it all together

Full customer health report

This query combines joins, predefined filters, window functions, and measures in a single query:

This returns the top 3 customers by revenue in each region, with their account manager, using only semantic references and no raw SQL logic.

Last updated