Advertisement
roganhamby

Circs by Author

Feb 6th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. -- some ineffecient stuff to move things to temp tables simply because our main tables are so large now
  3. -- these reports give me a analysis for a library system of what their highest circulating bib records and then authors are
  4.  
  5. -- I need a copy location crib sheet
  6.  
  7. select * from asset.copy_location acl
  8. join actor.org_unit child on child.id = acl.owning_lib
  9. join actor.org_unit parent on parent.id = child.parent_ou
  10. where parent.shortname = 'YCL'
  11. ;
  12.  
  13. -- YCL's are named consistently so I'm going to filter by copy location name
  14. -- if the systems were not named consistently I would cheat and map them, take out everything that's not adult and not fiction
  15.  
  16. create table rogan.ycl_circs as
  17. select circ.*
  18. from action.circulation circ
  19. join asset.copy ac on ac.id = circ.target_copy
  20. join asset.call_number call on call.id = ac.call_number
  21. join actor.org_unit child on child.id = circ.circ_lib
  22. join actor.org_unit parent on parent.id = child.parent_ou
  23. join asset.copy_location acl on acl.id = ac.location
  24. where parent.shortname = 'YCL' and date(circ.xact_start) >= '2013-01-01' and date(circ.xact_start) <= '2013-12-31'
  25. and acl.name like 'Adult%' and acl.name not ilike '%DVD%' and acl.name not ilike '%non%' and acl.name not ilike '%periodical%' and acl.name not ilike '%books on%'
  26. ;
  27.  
  28. -- now I need to find the bibs of each item
  29.  
  30. create table rogan.ycl_authors as
  31. select circ.id as "circ_id", ac.id as "copy_id", call.id as "call_id", msr.id as "bib_id", msr.title, msr.author
  32. from rogan.ycl_circs circ
  33. join asset.copy ac on ac.id = circ.target_copy
  34. join asset.call_number call on call.id = ac.call_number
  35. join reporter.materialized_simple_record msr on msr.id = call.record
  36. ;
  37.  
  38. -- now let's get counts of them
  39.  
  40. create table rogan.ycl2013 as
  41. select count(circ.id), ycl.author, ycl.title
  42. from rogan.ycl_circs circ
  43. join rogan.ycl_authors ycl on ycl.copy_id = circ.target_copy
  44. group by 2, 3
  45. having count(circ.id) > 24
  46. ;
  47.  
  48. drop table rogan.ycl_authors;
  49. drop table rogan.ycl_circs;
  50.  
  51. -- clean out the videos
  52.  
  53. delete from rogan.ycl2013 where author is null;
  54.  
  55. create table rogan.ycl2013_authors as
  56. select sum(ycl.count) as "circ_count", ycl.author
  57. from rogan.ycl2013 ycl
  58. group by 2
  59. ;
  60.  
  61. select count(circ_count) from rogan.ycl2013_authors where circ_count >= 75;
  62.  
  63. select * from rogan.ycl2013_authors order by 2 ASC;
  64.  
  65. select * from rogan.ycl2013_authors order by 1 DESC limit 10;
  66.  
  67.  
  68. -- now I need to get rid of those that are juvenile only
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement