Quality & InspectionFree generatorPDF, Excel, Word exportAerospace

NCR Trend SQL Query Generator (Pareto by Supplier, Part, Cause)

A Pareto of nonconformances by supplier, part or cause tells you where corrective action effort pays back. This generator writes a portable SQL query for it, using your own table and column names.

Fill in

Your table name; generic by design

Generated code
Download:

NCR Pareto query

-- NCR Pareto by supplier_id, 2026-01-01 to 2026-09-30
-- Table and column names are generic. Replace with your schema.
SELECT
  supplier_id AS category,
  COUNT(*) AS ncr_count,
  SUM(qty_rejected) AS total_qty_rejected,
  ROUND(100.0 * COUNT(*) / SUM(COUNT(*)) OVER (), 1) AS pct_of_total,
  ROUND(100.0 * SUM(COUNT(*)) OVER (ORDER BY COUNT(*) DESC ROWS UNBOUNDED PRECEDING) / SUM(COUNT(*)) OVER (), 1) AS cumulative_pct
FROM quality_ncr
WHERE ncr_date >= '2026-01-01'
  AND ncr_date <= '2026-09-30'
GROUP BY supplier_id
ORDER BY ncr_count DESC
LIMIT 10;

Monthly trend variant

-- Monthly NCR count trend
SELECT
  EXTRACT(YEAR FROM ncr_date) AS yr,
  EXTRACT(MONTH FROM ncr_date) AS mon,
  COUNT(*) AS ncr_count
FROM quality_ncr
WHERE ncr_date >= '2026-01-01'
  AND ncr_date <= '2026-09-30'
GROUP BY EXTRACT(YEAR FROM ncr_date), EXTRACT(MONTH FROM ncr_date)
ORDER BY yr, mon;

Syntax uses ANSI window functions with LIMIT, which works in PostgreSQL, MySQL 8 and similar. For SQL Server replace LIMIT with TOP, and for Oracle use FETCH FIRST. Table and column names are placeholders. Test on a copy and in read-only mode first.

Ask your quality data questions in plain language

Optional: we can show a read-only natural language layer over your NCR data.

Optional. The tool and every export work without this. No spam.

How to use the generator

Enter the name of your NCR table and the columns holding the date, the grouping field and the rejected quantity. Choose the date window and how many rows to return, then copy the SQL. The first block ranks categories by NCR count with a percent of total and cumulative percent, the numbers needed to draw a Pareto chart. The second block gives a monthly trend you can paste into a spreadsheet or BI tool.

Reading a Pareto result

Look at the cumulative percentage column. The few categories that reach about eighty percent of NCRs are your focus list. Rank by count first, then check quantity and cost, since a supplier with few NCRs but large scrap value may matter more. Trend the monthly block after a corrective action to see whether the count actually falls.

  • Use consistent cause codes before trusting the chart
  • Separate supplier, in-process and customer NCRs
  • Review by value as well as count

Adapting to your ERP or QMS

ERP schemas vary widely. Quality modules in SAP, Oracle, Epicor or SyteLine each use their own table and field names, so this tool uses generic placeholders rather than guessing. Ask your administrator for the NCR header and detail tables, and join to the vendor and item masters if you want names instead of codes.

Common mistakes

Mixing closed and voided NCRs, counting an NCR once per line when you want one per record, and using free-text cause fields that cannot be grouped all distort the chart. Filter status deliberately and standardize cause codes.

Frequently Asked Questions

Will this run on my database as is?

Probably not without edits. Table and column names are placeholders, and window function and limit syntax vary by database. Adjust names and the row limit clause for your platform.

Does it need write access?

No. It is a read-only SELECT. Run it with a read-only account against a reporting copy where possible.

How do I get a Pareto chart?

Paste the result into Excel and chart the count as columns and the cumulative percent as a line on a secondary axis.

Why generic names?

Quality tables differ by ERP and version. Using made-up vendor-specific names would be misleading, so you map your own schema.

If NCR reporting is stuck in spreadsheets, we can discuss read-only queries or an AI assistant over your quality data on-premises.