Visual Pivot Table Builder

Paste or upload your data, pick which fields are rows, columns, and values, choose your aggregate — and instantly see a rendered pivot table alongside the SQL query that reproduces it in your database.

v5 — multi-measure
1
Load Data
2
Configure Fields
3
Pivot & SQL
📄
Drop a CSV file here
or click to browse — .csv, .tsv, .txt
Try a sample:
OR PASTE DATA BELOW

What This Tool Does

Generates SQL PIVOT queries visually — enter your source table, pivot column, row label, and aggregate function, and the tool writes the correct PIVOT syntax for your target database dialect.

Who This Is For

  • Data analysts who need crosstab reports but struggle with PIVOT syntax
  • SQL developers who rarely write PIVOT queries and need a verified template
  • Business intelligence engineers generating pivot SQL for reporting layers
  • SQL learners studying the PIVOT pattern through concrete, executable examples

Example: Input: Source: sales table · Row: region · Column: quarter · Aggregate: SUM(revenue) → Output: A complete SQL PIVOT query with the correct syntax for MySQL, PostgreSQL, or SQL Server — ready to run

📚 New tutorial: How to Use the Visual Pivot Table Builder — Step-by-Step with Screenshots — three fully worked examples (sales by region, headcount by department, order status breakdown) with screenshots of every step.

Visual to SQL Workflow

Build visually, then generate production SQL:

What Is a Pivot Table?

A pivot table rotates data from a tall, normalised format into a wide cross-tabulation. Instead of rows like East, Q1, 12400 and West, Q1, 15200, a pivot surfaces those side by side: one row for each region, one column for each quarter, with the aggregate value in each cell.

This tool does two things simultaneously: it renders the pivot table visually from your data, and it generates the SQL query that would reproduce the same result inside your database — whether that's SQL Server, PostgreSQL, MySQL, or a generic ANSI-compatible engine.

How the Fields Work

How the SQL Is Generated

SQL Server (T-SQL) has a native PIVOT operator. The output wraps your table in a CTE, applies PIVOT(AGG(value) FOR colField IN ([v1],[v2]...)) with the actual distinct column values from your data hardcoded in the IN clause.

PostgreSQL and MySQL don't have a native PIVOT operator — the tool generates equivalent conditional aggregation: one SUM(CASE WHEN col_field = 'value' THEN value_field END) expression per pivot column. This is standard ANSI SQL and runs in any database.

The SQL uses the actual distinct values found in your data, so the output is specific to your dataset and is ready to run — not a template you have to fill in.

Frequently Asked Questions

What data formats can I paste?
Comma-separated (CSV) or tab-separated (TSV). The first row must be the column headers. When you copy a range from Excel or Google Sheets with Ctrl+C, the clipboard contains tab-separated data — paste it directly into the text area.
How many distinct column values can the pivot handle?
There is no hard limit, but pivot tables with more than 20-30 column values become difficult to read on screen. The SQL script handles any number of distinct values — each becomes one CASE WHEN expression or one value in the IN clause.
What happens when a cell has no matching data?
Empty cells display a dash (—) in the visual pivot table. In the SQL, they produce NULL. The generated SQL wraps each column in COALESCE(…, 0) for SQL Server and ISNULL(…, 0) equivalents so you can replace NULL with zero if needed.
Can I use a text field as the Value Field with COUNT?
Yes. Any field can be the Value Field when the aggregate is COUNT or COUNT DISTINCT — the field doesn't need to be numeric. Only SUM and AVG require a numeric field; MIN and MAX work on text fields too (alphabetical ordering).
Does my data get sent to a server?
No. All parsing, pivoting, and SQL generation happens entirely in JavaScript in your browser tab. Nothing is transmitted. You can disconnect from the internet after the page loads and the tool will continue to work.

Related SQL Tools