Advertisement
roganhamby

Gale Patron Data - Branch Growth

Jan 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. drop table if exists rogan.gale;
  3.  
  4. create table rogan.gale as
  5. select aua.street1, aua.street2, aua.city, aua.state, aua.post_code, circ.id as circ_id, circ.xact_start,
  6. acl.name as "copy_location", ac.circ_modifier
  7. from action.circulation circ
  8. join actor.usr au on au.id = circ.usr
  9. join actor.usr_address aua on aua.id = au.mailing_address
  10. join actor.org_unit child_org on child_org.id = au.home_ou
  11. join actor.org_unit parent_org on parent_org.id = child_org.parent_ou
  12. join asset.copy ac on ac.id = circ.target_copy
  13. join asset.copy_location acl on acl.id = circ.copy_location
  14. where child_org.shortname = 'YCL-FM'  and extract(year from circ.xact_start) in ('2010','2011','2012','2013','2014','2015')
  15. and aua.county ilike 'York' and aua.post_code != '' and street1 != ''
  16. ;
  17.  
  18. -- be warned, in this stage you could add addresses that don't qualify the above criteria if you don't use the same filters
  19. insert into rogan.gale (street1, street2, city, state, post_code, circ_id, xact_start, copy_location, circ_modifier)  (
  20.         select aua.street1, aua.street2, aua.city, aua.state, aua.post_code, circ.id, circ.circ_time, nct.name, nct.name
  21.         from action.non_cataloged_circulation circ
  22.         join actor.usr au on au.id = circ.patron
  23.         join actor.usr_address aua on aua.id = au.mailing_address
  24.         join actor.org_unit child_org on child_org.id = au.home_ou
  25.         join actor.org_unit parent_org on parent_org.id = child_org.parent_ou
  26.         join config.non_cataloged_type nct on nct.id = circ.item_type
  27.         where child_org.shortname = 'YCL-FM'  and extract(year from circ.circ_time) in ('2010','2011','2012','2013','2014','2015')
  28.         and aua.county ilike 'York' and aua.post_code != '' and street1 != ''
  29. );
  30.  
  31. update rogan.gale set copy_location = 'STATS ONLY' where circ_modifier = copy_location;
  32.  
  33. insert into rogan.gale (street1, street2, city, state, post_code, circ_id, xact_start, copy_location, circ_modifier)  (
  34.         select aua.street1, aua.street2, aua.city, aua.state, aua.post_code, usr_act.id, usr_act.event_time, act_type.ewho, act_type.ewho
  35.         from actor.usr_activity usr_act
  36.         join actor.usr au on au.id = usr_act.usr
  37.                 join actor.usr_address aua on aua.id = au.mailing_address        
  38.                 join actor.org_unit child_org on child_org.id = au.home_ou
  39.                 join actor.org_unit parent_org on parent_org.id = child_org.parent_ou      
  40.                 join config.usr_activity_type act_type on act_type.id = usr_act.etype        
  41.                 where child_org.shortname = 'YCL-FM' and extract(year from usr_act.event_time) in ('2010','2011','2012','2013','2014','2015')
  42.                 and aua.county ilike 'York' and aua.post_code != '' and street1 != ''
  43.                 and act_type.ehow = 'sip2' and act_type.ewhat = 'verify'
  44. );
  45.  
  46.  
  47. -- cleans up SIP activity not tied to any discernable account
  48. -- should be redundant now with the criteria set above but still here just in case
  49. delete from rogan.gale where post_code = '99999';
  50.  
  51. -- clean out PO boxes which don't map correctly
  52. delete from rogan.gale where street1 ilike 'PO %' or street1 ilike 'P.O%';
  53.  
  54. -- cleanup for conformity
  55. update rogan.gale set street2 = null where street2 = '';
  56.  
  57. -- ----------------------------------------------------------------------------------------------------------
  58. -- Patron profiles gale report ------------------------------------------------------------------------------
  59. -- ----------------------------------------------------------------------------------------------------------
  60.  
  61. select street1 as "ADDRESS", street2 as "SUITE (OPTIONAL)", city as "CITY", state as "STATE", post_code as "ZIP CODE",
  62. count(circ_id) as "CHECKOUTS (OPTIONAL)", max(date(xact_start)) as "DATE"
  63. from rogan.gale
  64. -- where state ilike 'sc' or state ilike 'nc'
  65. -- where post_code ilike '297%'
  66. group by 1, 2, 3, 4, 5;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement