Advertisement
roganhamby

Summer Reading Stats

Sep 1st, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. drop table if exists rogan.action_circulation;
  3.  
  4. /* create a table and map per circulation */
  5.  
  6. create table rogan.action_circulation as
  7. select * from action.circulation where date(create_time) between '2015-06-01' and '2015-08-31';
  8.  
  9. alter table rogan.action_circulation add column print boolean default TRUE;
  10.  
  11. /* map print = true based on these circ mods */
  12.  
  13. /* then it got a lot more manual looking at shelving locations.  I made a review of a sample of five thousand shelving
  14. location entries and based on that assumed that copies with shelving locations saying AUDIO or VIDEO or EQUIPMENT
  15. should be changed to non-print then I re-ran it with exclusions and found more like DVD */
  16.  
  17. update rogan.action_circulation set print = false where target_copy in (
  18.         select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id
  19.         join asset.copy_location acl on acl.id = ac.location
  20.         where ac.circ_modifier in ('ELECTRONIC EQUIPMENT','VIDEO','AUDIO','EREADER','PLAYAWAY','AUDIO BOOK',
  21.         'THEME KIT','EQUIPMENT','KIT','INTERNET','GAME','LEASE DVD')
  22.         or (acl.name ilike '%audio%' or acl.name ilike '%video%' or acl.name ilike '%equipment%' or acl.name ilike '%dvd%'
  23.         or acl.name ilike '%books on cd%' or acl.name ilike '%books on cassette%' or acl.name ilike '%music cd%' or
  24.         acl.name ilike '%adult 360%' or acl.name ilike '%adult ps2%')
  25. );
  26.  
  27. /* now I will go through all distinct occurances of the library systems and these circ mods with other shelving
  28. location names excluding those that had audio, video or unknown in the name */
  29.  
  30. select DISTINCT aou.parent_ou, ac.circ_modifier, acl.name
  31. from asset.copy ac
  32. join actor.org_unit aou on aou.id = ac.circ_lib
  33. join asset.copy_location acl on acl.id = ac.location
  34. where ac.circ_modifier in ('21 DAY LEASE','14 DAY LEASE','7 DAY LEASE','28 DAY','14 DAY','21 DAY','7 DAY','RENTAL')
  35. and acl.name not ilike '%audio%' and acl.name not ilike '%audio%' and acl.name not ilike '%video%'
  36. and acl.name not ilike '%equipment%' and acl.name not ilike '%dvd%' and acl.name not ilike '%books on cd%'
  37. and acl.name not ilike '%books on cassette%' and acl.name not ilike '%music cd%' and  
  38. acl.name not ilike '%adult 360%' and acl.name not ilike '%adult ps2%'
  39. order by 1, 2;
  40.  
  41. alter table rogan.action_circulation add column adult boolean default true;
  42. alter table rogan.action_circulation add column ya boolean default false;
  43. alter table rogan.action_circulation add column juv boolean default false;
  44.  
  45. update rogan.action_circulation set adult = false, ya = true where target_copy in (
  46.         select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id
  47.         join asset.copy_location acl on acl.id = ac.location
  48.         where acl.name ilike '%young%'
  49. );
  50.  
  51.  
  52. update rogan.action_circulation set adult = false, juv = true where target_copy in (
  53.         select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id
  54.         join asset.copy_location acl on acl.id = ac.location
  55.         where acl.name ilike '%juv%'
  56. );
  57.  
  58. SELECT juv_a.shortname as "Library",  
  59. juv_a.circs as "Juvenile Print Circs", juv_not_a.circs as "Juvenile Non-Print Circs",
  60. juv_a.circs+juv_not_a.circs+coalesce(non.circs,0) as "Total Juvenile Circs",
  61. ya_a.circs as "YA Print Circs", ya_not_a.circs as "YA Non-Print Circs",
  62. ya_a.circs+ya_not_a.circs+coalesce(non.circs,0) as "Total YA Circs",
  63. adult_a.circs as "Adult Print Circs", adult_not_a.circs as "Adult Non-Print Circs",
  64. adult_a.circs+adult_not_a.circs+coalesce(non.circs,0) as "Total Adult Circs"
  65. FROM (
  66.         SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  67.         FROM rogan.action_circulation circ
  68.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  69.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  70.         WHERE circ.print = true and circ.juv = true
  71.         GROUP BY 2
  72. ) juv_a
  73. left join (
  74.         SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  75.         FROM rogan.action_circulation circ
  76.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  77.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  78.         WHERE circ.print = true and circ.adult = true
  79.         GROUP BY 2
  80. ) adult_a on adult_a.shortname = juv_a.shortname
  81. left join (
  82.         SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  83.         FROM rogan.action_circulation circ
  84.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  85.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  86.         WHERE circ.print = false and circ.juv = true
  87.         GROUP BY 2
  88. ) juv_not_a on juv_not_a.shortname = juv_a.shortname
  89. left join (
  90.         SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  91.         FROM rogan.action_circulation circ
  92.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  93.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  94.         WHERE circ.print = false and circ.adult = true
  95.         GROUP BY 2
  96. ) adult_not_a on adult_not_a.shortname = juv_a.shortname
  97. left join (
  98.         SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  99.         FROM rogan.action_circulation circ
  100.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  101.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  102.         WHERE circ.print = true and circ.ya = true
  103.         GROUP BY 2
  104. ) ya_a on ya_a.shortname = juv_a.shortname
  105. left join (
  106.         SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  107.         FROM rogan.action_circulation circ
  108.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  109.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  110.         WHERE circ.print = false and circ.ya = true
  111.         GROUP BY 2
  112. ) ya_not_a on ya_not_a.shortname = juv_a.shortname
  113. left join (  SELECT coalesce(count(circ.id),0) AS circs, org2.shortname AS shortname
  114.         FROM action.non_cataloged_circulation circ
  115.         left JOIN actor.org_unit org ON org.id = circ.circ_lib
  116.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  117.         where date(circ.circ_time) >= '2015-06-01' AND date(circ.circ_time) <= '2015-08-31'
  118.         GROUP BY 2
  119. ) non on non.shortname = juv_a.shortname
  120. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement