Developer ToolsFree generatorPDF, Excel, Word exportPhotonics and Optics

Photonics Lot Yield and Test Results SQL Query Generator

This generator produces three SQL queries that most photonics and electronics quality teams need every week: first-pass yield by lot, fallout by test step, and a defect Pareto. You type in your own table and column names, copy the SQL, and run it against a read replica of your MES, test database or ERP quality tables.

Fill in

One row per unit per test step

Values assumed to be PASS or FAIL

Generated code
Download:

1. First-pass yield by lot

-- Units whose FIRST recorded result per step was PASS across all steps
SELECT
  lot_number AS lot,
  COUNT(DISTINCT serial_number) AS units_tested,
  COUNT(DISTINCT CASE WHEN result = 'FAIL' THEN serial_number END) AS units_with_a_fail,
  100.0 * (COUNT(DISTINCT serial_number)
    - COUNT(DISTINCT CASE WHEN result = 'FAIL' THEN serial_number END))
    / NULLIF(COUNT(DISTINCT serial_number), 0) AS first_pass_yield_pct
FROM test_results
WHERE tested_at >= '2026-09-01'
  AND tested_at < DATEADD(day, 1, '2026-09-30')
GROUP BY lot_number
ORDER BY first_pass_yield_pct ASC;

2. Fallout by test step

SELECT
  test_step AS test_step,
  COUNT(*) AS tests_run,
  SUM(CASE WHEN result = 'FAIL' THEN 1 ELSE 0 END) AS fails,
  100.0 * SUM(CASE WHEN result = 'FAIL' THEN 1 ELSE 0 END)
    / NULLIF(COUNT(*), 0) AS fail_rate_pct
FROM test_results
WHERE tested_at >= '2026-09-01'
  AND tested_at < DATEADD(day, 1, '2026-09-30')
GROUP BY test_step
ORDER BY fails DESC;

3. Defect Pareto with cumulative percent

WITH d AS (
  SELECT defect_code AS defect, COUNT(*) AS n
  FROM test_results
  WHERE result = 'FAIL'
    AND defect_code IS NOT NULL
    AND tested_at >= '2026-09-01'
    AND tested_at < DATEADD(day, 1, '2026-09-30')
  GROUP BY defect_code
)
SELECT
  defect,
  n,
  100.0 * n / SUM(n) OVER () AS pct,
  100.0 * SUM(n) OVER (ORDER BY n DESC ROWS UNBOUNDED PRECEDING) / SUM(n) OVER () AS cumulative_pct
FROM d
ORDER BY n DESC;

Table and column names here are generic placeholders, not a specific ERP or MES schema, so map them to your own. DATEADD and the window syntax shown are SQL Server style, so adapt date functions for Oracle, PostgreSQL or MySQL. First-pass yield here counts a unit as failed if any recorded fail exists, so retests should be flagged with an attempt column if you need strict first-attempt logic. Run on a read-only replica first.

Yield reporting on your ERP data

Want yield, fallout and Pareto answers straight from your own ERP and test data? Tell us about your systems and we will outline options. Optional.

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

How to use it

Enter the name of the table that holds one row per unit per test step, then the lot, serial, step, result, defect and date columns. Set the date window and copy each query. The queries assume results are stored as PASS or FAIL text, so edit the comparison values if your system uses codes. Always run new SQL on a reporting copy or with read-only credentials before pointing it at production.

  • Use a read-only database account
  • Map generic column names to your schema
  • Adapt DATEADD and window functions to your database
  • Add a product or part filter for large databases

What the three queries tell you

First-pass yield by lot ranks lots from worst to best so you can see which builds need investigation. Fallout by test step shows where in the flow the losses occur, such as power, spectrum, alignment or leak test for modules. The defect Pareto puts failures in order with a cumulative percentage, which usually shows that three or four codes drive most of the loss, and tells you where to focus corrective action.

First-pass yield and rolled throughput

First-pass yield is units passing with no rework or retest divided by units started. Rolled throughput yield multiplies the first-pass yield of each step, so a flow with five steps at 95 percent each yields about 77 percent, not 95. If your database logs attempts, extend the queries with an attempt number and count only attempt one, so retests do not hide true process loss.

Common mistakes

Counting rows instead of distinct units inflates fallout when a unit is tested several times. Mixing different part numbers in one yield figure hides product-specific problems. Excluding scrapped units that never reached final test makes yield look better than it is. Make sure date filters use the test date, not the lot creation date, and document your yield definition so reports compare like with like.

Frequently Asked Questions

Will these queries work on my ERP or MES schema?

They use generic names, so you must map the table and column names to your own schema. The logic works with any database that stores one test result per unit and step. Date and window functions may need adjusting for Oracle, PostgreSQL or MySQL.

How is first-pass yield calculated here?

A unit counts as a failure if any FAIL result exists for it in the date window, and yield is units without a fail divided by distinct units tested. If you retest failures, add an attempt column and count only first attempts for a stricter definition.

Is it safe to run generated SQL on production?

The queries only read data, but heavy aggregations can slow a busy system. Run them on a replica or during quiet hours, with a read-only account and a limited date range. Review the SQL before execution, as you would any script.

Why do I need a defect Pareto?

A Pareto ranks defect causes by count, with a cumulative percentage line. It usually shows that a small number of causes create most of the loss, so you can put corrective actions where they pay back most, rather than spreading effort across every defect code.

If you want these yield and fallout questions answered in plain language directly from your ERP, MES and test data, we can build a private, read-only assistant on your own infrastructure. Reach out to discuss it.