Advertisement
roganhamby

Public Relations Reports

Dec 30th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Public Relations reports organized by dates used
  2.  
  3. -- anytime -> top ten titles by circulation in date range given
  4. -- by default it's calculating for the last year but you could easily modify it to look within
  5. -- specific dates
  6.  
  7. select count(circ.id), call.record,
  8. array_accum(DISTINCT(maf.value)) AS "Author",
  9. array_accum(DISTINCT(mtf.value)) AS "Title"
  10. from action.circulation circ
  11. join asset.copy copy on copy.id = circ.target_copy
  12. join asset.call_number call on call.id = copy.call_number
  13. join metabib.author_field_entry maf ON call.record = maf.source
  14. join metabib.title_field_entry mtf ON call.record = mtf.source
  15. where circ.xact_start > now() - interval '1 year'
  16. group by call.record
  17. order by 1 desc
  18. limit 11
  19. ;
  20.  
  21.  
  22. -- How about Christmas titles in the holiday Season? These are the top 10.
  23.  
  24. select count(circ.id), call.record,
  25. array_accum(DISTINCT(maf.value)) AS "Author",
  26. array_accum(DISTINCT(mtf.value)) AS "Title"
  27. from action.circulation circ
  28. join asset.copy copy on copy.id = circ.target_copy
  29. join asset.call_number call on call.id = copy.call_number
  30. join metabib.author_field_entry maf ON call.record = maf.source
  31. join metabib.title_field_entry mtf ON call.record = mtf.source
  32. where date(circ.xact_start) > '2013-09-30' and date(circ.xact_start) < '2014-01-01'
  33. and mtf.value ilike '%christmas%'
  34. group by call.record
  35. order by 1 desc
  36. limit 11
  37. ;
  38.  
  39. -- Or maybe just a raw count
  40.  
  41. select count(circ.id)
  42. from action.circulation circ
  43. join asset.copy copy on copy.id = circ.target_copy
  44. join asset.call_number call on call.id = copy.call_number
  45. join metabib.author_field_entry maf ON call.record = maf.source
  46. join metabib.title_field_entry mtf ON call.record = mtf.source
  47. where date(circ.xact_start) > '2013-09-30' and date(circ.xact_start) < '2014-01-01'
  48. and mtf.value ilike '%christmas%'
  49. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement