Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT acp.circ_lib, COUNT(DISTINCT acp.id)
- FROM asset.copy acp
- JOIN asset.call_number acn ON acn.id = acp.call_number
- JOIN biblio.monograph_part bmp ON acn.record = bmp.record
- LEFT JOIN asset.copy_part_map acpm ON acpm.target_copy = acp.id -- AND acpm.part = bmp.id -- Add this piece to limit to "and the part is on the correct bib", though if that changes numbers you have other issues.
- JOIN asset.copy_location acl ON acl.id = acp.location
- WHERE NOT acp.deleted AND acpm IS NULL
- AND acp.holdable AND acl.holdable -- Skip copies that are not holdable by copy or location, because who cares about them?
- --AND acp.circ_lib = 97
- --AND acp.circ_modifier IN ('movief', 'movienf', 'jmovief', 'jmovienf', 'movieseries');
- GROUP BY acp.circ_lib
- WITH bib_has_parts AS (
- SELECT bmp.record, count(DISTINCT acpm.id) AS part_maps
- FROM biblio.monograph_part bmp
- LEFT JOIN asset.copy_part_map acpm ON acpm.part = bmp.id
- GROUP BY 1
- )
- SELECT (actor.org_unit_ancestor_at_depth(acp.circ_lib, 1)).shortname, COUNT(DISTINCT acp.id) AS copies_sans_parts, COUNT(DISTINCT CASE WHEN bhp.part_maps > 0 THEN NULL ELSE acp.id END) AS copies_sans_parts_with_parted_copies
- FROM asset.copy acp
- JOIN asset.call_number acn ON acn.id = acp.call_number
- JOIN bib_has_parts bhp ON bhp.record = acn.record
- LEFT JOIN asset.copy_part_map acpm ON acpm.target_copy = acp.id
- JOIN asset.copy_location acl ON acl.id = acp.location
- JOIN config.copy_status ccs ON ccs.id = acp.status
- WHERE NOT acp.deleted AND acpm IS NULL
- AND acp.holdable AND acl.holdable AND ccs.holdable -- Skip copies that are not holdable by copy or location, because who cares about them?
- --AND acp.circ_lib = 97
- --AND acp.circ_modifier IN ('movief', 'movienf', 'jmovief', 'jmovienf', 'movieseries');
- GROUP BY 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement