Developer ToolsFree generatorPDF, Excel, Word export

ERP Selection Scoring SQL Generator: Weighted Vendor Ranking Query

A spreadsheet works for a three-vendor selection, but once many people score hundreds of criteria, a small database makes the maths auditable. This generator produces the schema and the ranking queries.

Fill in

Schema that will hold the scoring tables.

Generated code
Download:

Create tables

CREATE SCHEMA erp_selection;

CREATE TABLE erp_selection.vendor (
  vendor_id    INT PRIMARY KEY,
  vendor_name  VARCHAR(120) NOT NULL
);

CREATE TABLE erp_selection.criterion (
  criterion_id   INT PRIMARY KEY,
  category       VARCHAR(60) NOT NULL,
  criterion_name VARCHAR(160) NOT NULL,
  weight         DECIMAL(6,2) NOT NULL CHECK (weight > 0),
  is_mandatory   SMALLINT NOT NULL DEFAULT 0
);

CREATE TABLE erp_selection.score (
  vendor_id    INT NOT NULL REFERENCES erp_selection.vendor (vendor_id),
  criterion_id INT NOT NULL REFERENCES erp_selection.criterion (criterion_id),
  scorer       VARCHAR(80) NOT NULL,
  score        DECIMAL(4,1) NOT NULL CHECK (score >= 0 AND score <= 5),
  comment      VARCHAR(400) NULL,
  PRIMARY KEY (vendor_id, criterion_id, scorer)
);

Weighted ranking query

WITH avg_score AS (
  SELECT vendor_id, criterion_id, AVG(score) AS avg_s
  FROM erp_selection.score
  GROUP BY vendor_id, criterion_id
)
SELECT v.vendor_name,
       ROUND(100.0 * SUM(a.avg_s * c.weight) / (SUM(c.weight) * 5), 1) AS weighted_pct
FROM avg_score a
JOIN erp_selection.criterion c ON c.criterion_id = a.criterion_id
JOIN erp_selection.vendor v ON v.vendor_id = a.vendor_id
GROUP BY v.vendor_name
ORDER BY weighted_pct DESC
FETCH FIRST 5 ROWS ONLY;

Mandatory criteria gate and category breakdown

-- Vendors that scored below 2 on any mandatory criterion (average across scorers)
SELECT v.vendor_name, c.criterion_name, AVG(s.score) AS avg_s
FROM erp_selection.score s
JOIN erp_selection.criterion c ON c.criterion_id = s.criterion_id
JOIN erp_selection.vendor v ON v.vendor_id = s.vendor_id
WHERE c.is_mandatory = 1
GROUP BY v.vendor_name, c.criterion_name
HAVING AVG(s.score) < 2;

-- Weighted percent by category
SELECT v.vendor_name, c.category,
       ROUND(100.0 * SUM(s.score * c.weight) / (SUM(c.weight) * 5), 1) AS category_pct
FROM erp_selection.score s
JOIN erp_selection.criterion c ON c.criterion_id = s.criterion_id
JOIN erp_selection.vendor v ON v.vendor_id = s.vendor_id
GROUP BY v.vendor_name, c.category
ORDER BY v.vendor_name, c.category;

Written in standard SQL with FETCH FIRST, which runs on PostgreSQL, Oracle 12c+ and SQL Server 2012+ (with ORDER BY). On MySQL replace FETCH FIRST with LIMIT. The category query averages every individual score row; if scorers differ in count per criterion, aggregate by scorer first. Review against your own engine before use.

Ask your selection data in plain language

An optional look at natural-language querying over your own databases, on-premises.

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

How to use the generator

Set a schema name, the top score on your scale and the number of vendors to return, then copy the three blocks. Run the first to create the tables, load vendors and criteria with weights, and have each committee member insert scores. The second block returns a ranking by weighted percentage. The third lists any vendor that failed a mandatory criterion and shows a category breakdown for the steering group.

How the weighted score works

Each criterion's scores are averaged across committee members so that no single scorer dominates. The average is multiplied by the criterion weight, summed, and divided by the maximum possible weighted total. The result is a percentage that is easy to compare between vendors. Weights can be any positive numbers; they are normalized by the denominator, so they do not need to add up to 100.

  • Average first, then weight
  • Keep the same scale for all criteria
  • Store comments next to scores for the audit trail

Mandatory gates and fairness

A high total can hide a fatal gap. Flag mandatory criteria and review those separately from the weighted ranking so a vendor that cannot meet a compliance need does not win on strengths elsewhere. For fairness, agree weights before any demos, lock them in the criterion table, and record who scored what so the decision can be defended later.

Common mistakes

The usual errors are changing weights after seeing results, scoring on different scales, and averaging category percentages rather than weighted scores. Also watch for missing scores: a vendor with fewer scored criteria looks artificially strong or weak depending on the formula. Require a complete score set before running the ranking.

Frequently Asked Questions

Which database does this SQL run on?

The schema and queries use standard SQL that runs on PostgreSQL and recent SQL Server and Oracle versions. For MySQL, replace the FETCH FIRST clause with LIMIT. Always test on a scratch schema before using it with real committee data.

Do weights need to add up to 100?

No. The query divides by the sum of weights times the maximum score, so any positive weights work. Using 100 as a total is simply convenient for explaining the model to stakeholders.

Why average scorers before weighting?

Averaging first gives each criterion one representative value, so a criterion scored by more people does not count for more than one scored by fewer. It also makes the result stable if scorers join late.

Can I use this for non-ERP selections?

Yes. The model is generic weighted scoring and works for any multi-criteria vendor or product evaluation. Rename the schema and adjust the categories to suit your project.

If you want ERP data and selection evidence queried in plain language rather than SQL, Netray can show how that works. The generated SQL runs entirely on your own database.