Query syntax
These examples target FastBI Lake. The sample lake.uploads.orders table has order_id, customer_id, order_date, country, status, and numeric revenue columns. Adapt them to your schema.
Select and filter
Section titled “Select and filter”Choose the fields you need. Use a half-open date range to include the start and exclude the next period’s start.
SELECT order_id, customer_id, revenueFROM lake.uploads.ordersWHERE order_date >= DATE '2026-09-01' AND order_date < DATE '2026-10-01' AND status = 'completed'ORDER BY revenue DESC, order_idLIMIT 100;For timestamp columns, use timestamp boundaries appropriate to your reporting timezone instead of assuming that a calendar date represents the same instant everywhere.
Group and aggregate
Section titled “Group and aggregate”WHERE filters input rows. HAVING filters grouped results. Every selected expression that is not aggregated should appear in GROUP BY.
SELECT country, COUNT(*) AS orders, SUM(revenue) AS revenue, AVG(revenue) AS average_order_valueFROM lake.uploads.ordersWHERE status = 'completed'GROUP BY countryHAVING COUNT(*) >= 10ORDER BY revenue DESCLIMIT 100;This assumes one row per order. On an order-line table, count distinct order IDs and account for how revenue is represented.
Join tables
Section titled “Join tables”Use INNER JOIN for matching rows and LEFT JOIN to retain all rows from the left-hand table.
SELECT o.order_id, c.segment, o.revenueFROM lake.uploads.orders AS oLEFT JOIN lake.uploads.customers AS c ON o.customer_id = c.customer_idLIMIT 100;The example assumes customers.customer_id is unique. If it is not, each matching customer row duplicates an order in the result and can inflate totals.
Common table expressions
Section titled “Common table expressions”Use WITH to name intermediate results and make complex queries easier to review.
WITH customer_revenue AS ( SELECT customer_id, SUM(revenue) AS revenue FROM lake.uploads.orders WHERE status = 'completed' GROUP BY customer_id)SELECT customer_id, revenueFROM customer_revenueWHERE revenue > 1000ORDER BY revenue DESCLIMIT 100;Combine compatible results
Section titled “Combine compatible results”UNION ALL keeps all rows from both queries; UNION removes duplicate result rows. Align column positions and compatible types. Add a source label when you need to preserve provenance.
SELECT 'web' AS source, order_id, revenueFROM lake.uploads.web_ordersUNION ALLSELECT 'app' AS source, order_id, revenueFROM lake.uploads.app_ordersLIMIT 100;The final limit applies to the combined result. Add ordering when the selection must be deterministic.
Continue with the SQL syntax reference.