Assuming percentage of the total count:
SELECT (count(incidentnumber) FILTER (WHERE IncidentStationGround <> firstpumparriving_deployedfromstation)
* 100.0) / count(*) AS average
FROM incidents;
Multiply the result with a numeric
constant: 100.0
(with decimal point!) to implicitly cast the bigint
result of count()
to numeric
. (Or cast explicitly.)
round()
is optional. You get many decimal places without it.
Assuming that incidentnumber
is defined NOT NULL
, so count(*)
does the same as count(incidentnumber)
, just a bit faster. (A table definition would provide that information.)
Assuming Postgres 9.4 or later.
Related answer with links and alternative for older versions:
About round()
and numeric
: