Advertisement
roganhamby

Purchase Alert Report

Mar 1st, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- originally based on scripts by Dan Scott
  2.  
  3. -- warning, one of the weaknesses of the count for the system script is that it does not count low branches
  4. -- for example:
  5. -- if YCL has high counts on Hurricane Sisters with a total of 15 copies at 6 branches and 58 holds
  6. -- the report may only show 12 copies and 56 holds
  7. -- this is because one branch has 1 copy and less than 4 holds and the second branch has 2 copies and less than 8 holds
  8. -- also, it does not track metarecord holds at this time
  9.  
  10. -- system report
  11.  
  12. select bd.bib_id, parent.shortname as "org unit", bd.title, bd.author, bd.isbn, sum(bd.copies) as copies, sum(bd.holds_count) as "holds count",
  13. round(sum(bd.holds_count)/sum(bd.copies)) AS "holds count per copy"
  14.  from (
  15.     SELECT all_holds.bib_id, aou.id as org, rmsr.title, rmsr.author, rmsr.isbn,
  16.     COUNT(DISTINCT ac.id) AS "copies", COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id) AS "holds_count"
  17.     FROM ((
  18.     SELECT hold_request.target, hold_request.pickup_lib
  19.     FROM ACTION.hold_request
  20.     WHERE hold_request.hold_type = 'T'::TEXT
  21.     AND hold_request.fulfillment_time IS NULL
  22.     AND hold_request.cancel_time IS NULL
  23.     UNION ALL
  24.     SELECT bre.id, ahr.pickup_lib
  25.     FROM ACTION.hold_request ahr
  26.     JOIN asset.call_number acn ON ahr.target = acn.id
  27.     JOIN biblio.record_entry bre ON acn.record = bre.id
  28.     WHERE ahr.hold_type = 'V'::TEXT
  29.     AND ahr.fulfillment_time IS NULL
  30.     AND ahr.cancel_time IS NULL)
  31.     UNION ALL
  32.     SELECT bre.id, ahr.pickup_lib
  33.     FROM ACTION.hold_request ahr
  34.     JOIN asset.COPY ac ON ahr.target = ac.id
  35.     JOIN asset.call_number acn ON ac.call_number = acn.id
  36.     JOIN biblio.record_entry bre ON acn.record = bre.id
  37.     WHERE ahr.hold_type = 'C'::TEXT
  38.     AND ahr.fulfillment_time IS NULL
  39.     AND ahr.cancel_time IS NULL)
  40.     all_holds(bib_id, pickup_lib)
  41.     JOIN reporter.materialized_simple_record rmsr ON rmsr.id = all_holds.bib_id
  42.     JOIN actor.org_unit aou ON aou.id = all_holds.pickup_lib
  43.     JOIN asset.call_number acn ON acn.record = all_holds.bib_id
  44.     JOIN asset.COPY ac ON ac.call_number = acn.id
  45.     WHERE ac.circ_lib = all_holds.pickup_lib
  46.     GROUP BY 1, 2, 3, 4, 5
  47.     HAVING COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id) > 3
  48. ) bd
  49. join actor.org_unit child on child.id = bd.org
  50. join actor.org_unit parent on parent.id = child.parent_ou
  51. GROUP BY 1, 2, 3, 4, 5
  52. ORDER BY 2 ASC, 5 DESC
  53. ;
  54.  
  55.  
  56. SELECT all_holds.bib_id, aou.shortname AS "org unit", rmsr.title, rmsr.author, rmsr.isbn,
  57. COUNT(DISTINCT ac.id) AS "copies", COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id) AS "holds count",
  58. (COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id))/COUNT(DISTINCT ac.id) AS "holds count per copy"
  59. FROM ((
  60. SELECT hold_request.target, hold_request.pickup_lib
  61. FROM ACTION.hold_request
  62. WHERE hold_request.hold_type = 'T'::TEXT
  63. AND hold_request.fulfillment_time IS NULL
  64. AND hold_request.cancel_time IS NULL
  65. UNION ALL
  66. SELECT bre.id, ahr.pickup_lib
  67. FROM ACTION.hold_request ahr
  68. JOIN asset.call_number acn ON ahr.target = acn.id
  69. JOIN biblio.record_entry bre ON acn.record = bre.id
  70. WHERE ahr.hold_type = 'V'::TEXT
  71. AND ahr.fulfillment_time IS NULL
  72. AND ahr.cancel_time IS NULL)
  73. UNION ALL
  74. SELECT bre.id, ahr.pickup_lib
  75. FROM ACTION.hold_request ahr
  76. JOIN asset.COPY ac ON ahr.target = ac.id
  77. JOIN asset.call_number acn ON ac.call_number = acn.id
  78. JOIN biblio.record_entry bre ON acn.record = bre.id
  79. WHERE ahr.hold_type = 'C'::TEXT
  80. AND ahr.fulfillment_time IS NULL
  81. AND ahr.cancel_time IS NULL)
  82. all_holds(bib_id, pickup_lib)
  83. JOIN reporter.materialized_simple_record rmsr ON rmsr.id = all_holds.bib_id
  84. JOIN actor.org_unit aou ON aou.id = all_holds.pickup_lib
  85. JOIN asset.call_number acn ON acn.record = all_holds.bib_id
  86. JOIN asset.COPY ac ON ac.call_number = acn.id
  87. WHERE ac.circ_lib = all_holds.pickup_lib
  88. GROUP BY aou.shortname, all_holds.bib_id, rmsr.id, rmsr.title, rmsr.author, rmsr.isbn
  89. HAVING COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id) > 3
  90. ORDER BY aou.shortname, COUNT(all_holds.bib_id) DESC
  91. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement