BookNet Canada export: fix incorrect counts
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 13 Jan 2020 18:59:11 +0000 (13:59 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 13 Jan 2020 18:59:11 +0000 (13:59 -0500)
Various "COUNT(foo.id)" needed to become "COUNT(DISTINCT foo.id)"
when gathering lending counts to avoid duplication of rows due
to the outer joins in the query.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
booknet/booknet_exporter.pl

index 2d52b58..61c9293 100755 (executable)
@@ -276,12 +276,12 @@ sub get_lending_data {
     'SELECT 
         ssr.id
         ,ARRAY_TO_STRING(ssr.isbn,\';\') 
-        ,COUNT(circs.id)
-        ,COUNT(renews.id)
-        ,COUNT(holds.id)
-        ,COUNT(ac.id)
-        ,COUNT(circs_out.id)
-        ,COUNT(onorder.id)
+        ,COUNT(DISTINCT circs.id)
+        ,COUNT(DISTINCT renews.id)
+        ,COUNT(DISTINCT holds.id)
+        ,COUNT(DISTINCT ac.id)
+        ,COUNT(DISTINCT circs_out.id)
+        ,COUNT(DISTINCT onorder.id)
     FROM 
         (SELECT id, call_number FROM asset.copy WHERE circ_lib = ' . $org_id . ' AND deleted IS FALSE) ac 
     LEFT JOIN