Advertisement
roganhamby

Weeding Reports

Apr 23rd, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- this is the manually run report that shows circ count
  2. SELECT COUNT(acirc.id), ac.barcode AS "barcode", acl.NAME AS "shelving location",
  3. acn.label AS "call number", msr.title, MAX(acirc.xact_start) AS "last circulation"
  4. FROM asset.COPY ac
  5. JOIN asset.copy_location acl ON ac.LOCATION = acl.id
  6. LEFT JOIN ACTION.circulation acirc ON acirc.target_copy = ac.id
  7. JOIN asset.call_number acn ON acn.id = ac.call_number
  8. JOIN reporter.materialized_simple_record msr ON msr.id = acn.record
  9. JOIN actor.org_unit child ON child.id = ac.circ_lib
  10. JOIN actor.org_unit parent ON parent.id = child.parent_ou
  11. WHERE acl.NAME ILIKE 'Adult Fiction'
  12. AND acirc.xact_start IS NULL
  13. AND date(ac.create_date) <= NOW() - INTERVAL '3 years'
  14. AND child.shortname = 'YCL-RH'
  15. AND ac.deleted = FALSE
  16. and ac.status = 0
  17. GROUP BY 2, 3, 4, 5
  18. UNION ALL
  19. SELECT COUNT(acirc.id), ac.barcode AS "barcode", acl.NAME AS "shelving location",
  20. acn.label AS "call number", msr.title, MAX(acirc.xact_start) AS "last circulation"
  21. FROM asset.COPY ac
  22. JOIN asset.copy_location acl ON ac.LOCATION = acl.id
  23. LEFT JOIN ACTION.circulation acirc ON acirc.target_copy = ac.id
  24. JOIN asset.call_number acn ON acn.id = ac.call_number
  25. JOIN reporter.materialized_simple_record msr ON msr.id = acn.record
  26. JOIN actor.org_unit child ON child.id = ac.circ_lib
  27. JOIN actor.org_unit parent ON parent.id = child.parent_ou
  28. WHERE acl.NAME ILIKE 'Adult Fiction'
  29. AND date(ac.create_date) <= NOW() - INTERVAL '3 years'
  30. AND child.shortname = 'YCL-RH'
  31. AND ac.deleted = FALSE
  32. and ac.status = 0
  33. GROUP BY 2, 3, 4, 5
  34. HAVING MAX(acirc.xact_start) < NOW() - INTERVAL '3 years'
  35. ORDER BY 4
  36. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement