SQL examples

Practical SQL Examples for CSV, JSON, and Parquet Files

A compact collection of SQL patterns you can adapt for local file analysis in SQL for Files.

Published 2026-05-02·Updated 2026-05-02

Preview rows

Use a small LIMIT query whenever you start with a new file. It helps confirm table names, column names, and data shape.

SELECT *
FROM my_table
LIMIT 20;

Filter rows

WHERE filters rows before grouping or sorting. Combine conditions when you need a precise slice of a file.

SELECT *
FROM orders
WHERE status = 'paid'
  AND revenue >= 100
  AND order_date >= DATE '2026-01-01';

Group and aggregate

GROUP BY turns many detail rows into summaries. It is useful for totals by region, customer, product, status, or time period.

SELECT
  region,
  COUNT(*) AS rows,
  SUM(revenue) AS revenue
FROM orders
GROUP BY region
HAVING SUM(revenue) > 10000
ORDER BY revenue DESC;

Join related files

After adding multiple files, use JOIN to combine detail rows with lookup tables, metadata, or related entities.

SELECT
  orders.order_id,
  customers.customer_name,
  orders.revenue
FROM orders
LEFT JOIN customers
  ON orders.customer_id = customers.customer_id;

Work with dates

Date queries help with monthly reporting, retention checks, and time-window analysis.

SELECT
  date_trunc('month', order_date) AS month,
  COUNT(*) AS orders
FROM orders
GROUP BY month
ORDER BY month;

Rank rows with window functions

Window functions keep detail rows while calculating ranks, running totals, or comparisons inside groups.

SELECT
  customer_id,
  order_id,
  revenue,
  ROW_NUMBER() OVER (
    PARTITION BY customer_id
    ORDER BY revenue DESC
  ) AS revenue_rank
FROM orders;

Continue in the editor

Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.

Open editor