Fixes an issue with the item age calculation; not all items
will have a non-NULL active_date. This led to return
records with a NULL time circulating value, meaning
that they didn't get excluded by the percentile
filter.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
SUM(COALESCE(circ_time,0))::NUMERIC / SUM(age)::NUMERIC
FROM (SELECT cn.record AS bib,
cp.id,
- EXTRACT( EPOCH FROM AGE(cp.active_date) ) + 1 AS age,
+ EXTRACT( EPOCH FROM AGE(COALESCE(cp.active_date, cp.create_date)) ) + 1 AS age,
SUM( -- time copy spent circulating
EXTRACT(
EPOCH FROM