Developer ToolsFree generatorPDF, Excel, Word export

NCR Pareto and Repeat Offender SQL Generator

A Pareto of nonconformances tells you where to focus, and a repeat offender list shows which suppliers and parts keep coming back. This generator writes the SQL from your table and column names.

Fill in

Your actual table or view name

Generated code
Download:

1. Defect Pareto with cumulative percent

SELECT
  defect_code AS defect,
  COUNT(*) AS ncr_count,
  SUM(reject_qty) AS rejected_qty,
  ROUND(100.0 * SUM(COUNT(*)) OVER (ORDER BY COUNT(*) DESC, defect_code) / SUM(COUNT(*)) OVER (), 1) AS cumulative_pct
FROM quality_ncr
WHERE ncr_date >= DATE '2026-01-01'
GROUP BY defect_code
ORDER BY ncr_count DESC, defect_code;

2. Repeat offender suppliers

SELECT
  supplier_id AS supplier,
  COUNT(*) AS ncr_count,
  COUNT(DISTINCT part_number) AS distinct_parts,
  SUM(reject_qty) AS rejected_qty
FROM quality_ncr
WHERE ncr_date >= DATE '2026-01-01'
GROUP BY supplier_id
HAVING COUNT(*) >= 3
ORDER BY ncr_count DESC;

3. Repeat offender parts with defect mix

SELECT
  part_number AS part,
  defect_code AS defect,
  COUNT(*) AS ncr_count
FROM quality_ncr
WHERE ncr_date >= DATE '2026-01-01'
GROUP BY part_number, defect_code
HAVING COUNT(*) >= 3
ORDER BY ncr_count DESC, part_number;

Table and column names here are generic placeholders, not a specific ERP schema. Replace them with your own. Date literal syntax differs by database: DATE 'YYYY-MM-DD' works in PostgreSQL, Oracle and MySQL 8, while SQL Server prefers a plain 'YYYY-MM-DD' string or CAST. Test on a copy and review the query plan before running on a production system.

Review my NCR reporting queries

Optional: an expert looks at your schema and suggests a clean read-only quality view.

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

How to use the generator

Type the name of the table or view that holds your NCR records and the columns for defect code, supplier, part, rejected quantity and date. Choose a start date and a threshold for what counts as repeat. Copy the three queries into your SQL client, BI tool or ERP reporting tool. If your NCRs are spread over a header and a line table, create a view that joins them and point the generator at the view.

How the Pareto query works

The first query counts NCRs per defect code, then uses a window function to produce a running total divided by the grand total. Sorting by count descending means the cumulative percent shows how few defect types account for most of the problem. The usual reading is to start with the types that cover roughly the first 70 to 80 percent. The ORDER BY inside the window includes the defect code so ties produce stable results.

  • Count NCRs, not just quantities, to avoid one large lot dominating
  • Use rejected quantity to see impact on cost
  • Group similar defect codes before drawing conclusions

Data quality cautions

Pareto charts are only as good as the coding. If half your NCRs are coded Other, or inspectors use different codes for the same defect, the result misleads. Check the top codes against a sample of descriptions before acting. Also decide whether to count NCRs by date raised or date closed, and be consistent. For supplier decisions, compare against delivered quantity so a high-volume supplier is not unfairly flagged.

Frequently Asked Questions

Which databases does this SQL work on?

The window function syntax works on PostgreSQL, SQL Server 2012 and later, Oracle and MySQL 8. The DATE literal differs slightly, so adjust it if your database rejects it. See the notes under the generator.

Can I use this on SAP or Epicor tables?

Only after mapping the placeholders to real table and column names, or building a view. We do not assume a vendor schema here. Check your ERP data dictionary and run queries on a copy or reporting database.

What counts as a repeat offender?

That is your threshold. Three NCRs in the period is a common starting point, but low-volume suppliers may need a lower number, and you should normalise by delivered quantity before escalating.

How do I turn the result into a chart?

Paste the output into Excel and create a bar chart of ncr_count with cumulative_pct as a line on a secondary axis. That gives the classic Pareto chart.

If your NCR data sits in an ERP with awkward schemas, we can help build a clean read-only quality view that these queries can run on.