Advertisement
roganhamby

Statistics - Holds

Jan 13th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /* redoing old work in a cleaner way, Feb 2015
  3.  
  4. holds have different aspects people want to look at so this is a bit more complicated by definition
  5. I'm leanving out stats on frozen, canceled and expired holds as they overly complicate it
  6.  
  7. */
  8.  
  9. CREATE TABLE rogan.stats_holds (
  10.         id              serial,
  11.         holds           INT,
  12.         pickup_lib      INT,
  13.         source_lib      INT,
  14.         circ_modifier   TEXT,
  15.         location        INT,
  16.         stats_year      INT,
  17.         month           INT,
  18.         usr_profile     INT
  19. );
  20.  
  21. /* let's pull how holds were fulfilled, do it by source library to distributed library */
  22.  
  23. insert into rogan.stats_holds (holds, pickup_lib, source_lib, circ_modifier, location, stats_year, month, usr_profile)
  24. (
  25.     select count(ahr.id) as holds, ahr.pickup_lib, ac.circ_lib as source_lib,
  26.     ac.circ_modifier, acl.id as location, y.id as stats_year,
  27.     extract(month from ahr.request_time) as month, au.profile as usr_profile
  28.     from action.hold_request ahr
  29.     join actor.usr au on au.id = ahr.usr
  30.     join asset.copy ac on ac.id = ahr.current_copy
  31.     join asset.copy_location acl on acl.id = ac.location
  32.     JOIN rogan.statistical_years y ON y.id = 6
  33.     WHERE ahr.fulfillment_time >= y.year_start AND ahr.fulfillment_time <= y.year_end
  34.     group by 2, 3, 4, 5, 6, 7, 8
  35. );
  36.  
  37.  
  38. /* how many items did patrons get each year per library? can make it parents pretty easily or group by something like circ mods*/
  39.  
  40. select sum(holds), pickup_lib
  41. from rogan.stats_holds rsh
  42. where stats_year = 5
  43. group by 2;
  44.  
  45. select sum(holds), aou.parent_ou
  46. from rogan.stats_holds rsh
  47. join actor.org_unit aou on aou.id = pickup_lib
  48. where stats_year = 5
  49. group by 2;
  50.  
  51. select sum(holds), aou.parent_ou, circ_modifier
  52. from rogan.stats_holds rsh
  53. join actor.org_unit aou on aou.id = pickup_lib
  54. where stats_year = 5
  55. group by 2, 3;
  56.  
  57.  
  58. /* report 2 what holds did we fill? same as above but flip pickup for source*/
  59.  
  60. select sum(holds), source_lib
  61. from rogan.stats_holds rsh
  62. where stats_year = 5
  63. group by 2;
  64.  
  65. /* report 3 what ICLs came in for this we take the what did we fill and see where parents of the source and pickup differ */
  66.  
  67. select sum(holds), pickup_lib
  68. from rogan.stats_holds rsh
  69. join actor.org_unit aou_pickup on aou_pickup.id = pickup_lib
  70. join actor.org_unit aou_source on aou_source.id = source_lib
  71. where stats_year = 5 and aou_pickup.parent_ou != aou_source.parent_ou
  72. group by 2;
  73.  
  74.  
  75. /* report 3 what ICLs came in for this we take the what did we fill and see where parents of the source and pickup differ */
  76.  
  77. select sum(holds), source_lib, pickup_lib
  78. from rogan.stats_holds rsh
  79. join actor.org_unit aou_pickup on aou_pickup.id = pickup_lib
  80. join actor.org_unit aou_source on aou_source.id = source_lib
  81. where stats_year = 5 and aou_pickup.parent_ou != aou_source.parent_ou
  82. group by 2, 3;
  83.  
  84. -- lets make it county based and see who York gave stuff to
  85. select sum(holds), aou_source.parent_ou as source, aou_pickup.parent_ou as pickup
  86. from rogan.stats_holds rsh
  87. join actor.org_unit aou_pickup on aou_pickup.id = pickup_lib
  88. join actor.org_unit aou_source on aou_source.id = source_lib
  89. where stats_year = 5 and aou_pickup.parent_ou != aou_source.parent_ou
  90. and aou_source.parent_ou = 119
  91. group by 2, 3;
  92.  
  93. -- lets make it county based and see who York got stuff from
  94. select sum(holds), aou_source.parent_ou as source, aou_pickup.parent_ou as pickup
  95. from rogan.stats_holds rsh
  96. join actor.org_unit aou_pickup on aou_pickup.id = pickup_lib
  97. join actor.org_unit aou_source on aou_source.id = source_lib
  98. where stats_year = 5 and aou_pickup.parent_ou != aou_source.parent_ou
  99. and aou_pickup.parent_ou = 119
  100. group by 2, 3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement