SQL Workbench Embedded unpkg CDN

Interactive SQL execution in your browser using DuckDB WASM - loaded from unpkg CDN

How to use

Example 1: Basic Query

A simple SELECT query to get started. Try modifying the numbers!

SELECT
  'Hello' AS greeting,
  'World' AS target,
  42 AS answer,
  3.14159 AS pi;

Example 2: Data Generation

Generate a sequence of numbers and perform calculations:

SELECT
  n AS number,
  n * n AS square,
  n * n * n AS cube,
  CASE
    WHEN n % 2 = 0 THEN 'Even'
    ELSE 'Odd'
  END AS parity
FROM generate_series(1, 10) AS t(n);

Example 3: Aggregations

Group data and perform aggregations:

WITH sales_data AS (
  SELECT
    unnest(['Electronics', 'Clothing', 'Electronics', 'Food', 'Clothing', 'Electronics', 'Food', 'Food']) AS category,
    unnest([1200, 450, 890, 230, 620, 1500, 180, 340]) AS amount
)
SELECT
  category,
  COUNT(*) AS transaction_count,
  SUM(amount) AS total_sales,
  AVG(amount) AS avg_sale,
  MAX(amount) AS max_sale
FROM sales_data
GROUP BY category
ORDER BY total_sales DESC;

Example 4: Date Operations

Work with dates and time:

SELECT
  CURRENT_DATE AS today,
  CURRENT_DATE - INTERVAL '7 days' AS last_week,
  CURRENT_DATE + INTERVAL '30 days' AS next_month,
  EXTRACT(year FROM CURRENT_DATE) AS current_year,
  EXTRACT(month FROM CURRENT_DATE) AS current_month,
  EXTRACT(day FROM CURRENT_DATE) AS current_day;

Example 5: Window Functions

Use window functions for advanced analytics:

WITH employee_data AS (
  SELECT
    unnest(['Alice', 'Bob', 'Carol', 'David', 'Eve']) AS name,
    unnest(['Sales', 'Sales', 'Engineering', 'Engineering', 'Sales']) AS department,
    unnest([75000, 82000, 95000, 88000, 79000]) AS salary
)
SELECT
  name,
  department,
  salary,
  AVG(salary) OVER (PARTITION BY department) AS dept_avg_salary,
  RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank,
  RANK() OVER (ORDER BY salary DESC) AS company_rank
FROM employee_data
ORDER BY department, salary DESC;

Example 6: Custom Themes

Demonstrating custom theme usage with different color schemes.

Ocean Theme (extends dark)

SELECT 'Ocean theme' AS theme_name, 'Extends dark theme' AS description;

Sunset Theme (standalone)

SELECT 'Sunset theme' AS theme_name, 'Standalone theme' AS description;