Advertisement
roganhamby

Annual State Statistics - Section F Collections

Apr 28th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Section F LIBRARY COLLECTIONS
  4.  
  5.             Books/Serials/Volumes - Physical print format
  6.             F1 Number added__________________________
  7.             F2 Number weeded__________________________
  8.             F3 TOTAL__________________________
  9.             Current Print Serial Subscriptions (physical format, newspaper and periodicals)
  10.             F4 Number added__________________________
  11.             F5 Number weeded__________________________
  12.             F6 TOTAL__________________________
  13.            
  14.             Audio materials (physical units containing music, spoken word, etc. on CD, cassette tape, etc.)
  15.             F7 Number of physical units added__________________________
  16.             F8 Number of physical units weeded__________________________
  17.             F9 TOTAL__________________________
  18.            
  19.             Video materials (physical units containing movies, TV shows, etc. on film, DVD, etc.)
  20.             F10 Number of physical units added__________________________
  21.             F11 Number of physical units weeded__________________________
  22.             F12 TOTAL physical units held__________________________
  23.  
  24. */
  25.  
  26.  
  27. /*
  28. total language materials (aka books) in collection at end of fiscal
  29. there isn't an "other" category for materials so everything else is grouped into physical print
  30. also adds in an estimate based on your non-cataloged circulation of those materials
  31. ------------------------------------------------------------------------------------------------------------------
  32. ------------------------------------------------------------------------------------------------------------------
  33. */
  34.  
  35.  
  36. DROP TABLE IF EXISTS rogan.asset_copy;
  37.  
  38. /* create a table and map per circulation */
  39.  
  40. CREATE TABLE rogan.asset_copy AS
  41. SELECT id, circ_lib, LOCATION, circ_modifier, deleted, create_date, edit_date FROM asset.COPY;
  42.  
  43. ALTER TABLE rogan.asset_copy ADD COLUMN book BOOLEAN DEFAULT TRUE;
  44. ALTER TABLE rogan.asset_copy ADD COLUMN serial BOOLEAN DEFAULT FALSE;
  45. ALTER TABLE rogan.asset_copy ADD COLUMN video BOOLEAN DEFAULT FALSE;
  46. ALTER TABLE rogan.asset_copy ADD COLUMN audio BOOLEAN DEFAULT FALSE;
  47.  
  48. UPDATE rogan.asset_copy SET book = FALSE WHERE circ_modifier IN
  49.         ('ELECTRONIC EQUIPMENT','EREADER','EQUIPMENT','INTERNET','THEME KIT','GAME');
  50.  
  51. UPDATE rogan.asset_copy SET serial = TRUE WHERE circ_modifier = 'MAGAZINE';
  52.  
  53. UPDATE rogan.asset_copy SET video = TRUE WHERE circ_modifier IN ('VIDEO','LEASE DVD');
  54.  
  55. UPDATE rogan.asset_copy SET audio = TRUE WHERE circ_modifier IN ('AUDIO','PLAYAWAY','AUDIO BOOK');
  56.  
  57. ALTER TABLE rogan.asset_copy ADD COLUMN location_name TEXT;
  58.  
  59. UPDATE rogan.asset_copy SET location_name = loc.NAME
  60. FROM (SELECT ac.id AS "ac_id", acl.NAME FROM rogan.asset_copy ac JOIN asset.copy_location acl ON acl.id = ac.LOCATION) loc
  61. WHERE loc.ac_id = id ;
  62.  
  63. UPDATE rogan.asset_copy SET video = TRUE WHERE circ_modifier IN ('21 DAY LEASE','14 DAY LEASE','7 DAY LEASE','28 DAY','14 DAY','21 DAY','7 DAY','RENTAL')
  64. AND (location_name ILIKE '%video%' OR location_name ILIKE '%dvd%');
  65.  
  66. UPDATE rogan.asset_copy SET audio = TRUE WHERE circ_modifier IN ('21 DAY LEASE','14 DAY LEASE','7 DAY LEASE','28 DAY','14 DAY','21 DAY','7 DAY','RENTAL')
  67. AND (location_name ILIKE '%audio%' OR location_name ILIKE '%books on%' OR location_name ILIKE '%music%');
  68.  
  69. UPDATE rogan.asset_copy SET book = FALSE WHERE circ_modifier IN ('21 DAY LEASE','14 DAY LEASE','7 DAY LEASE','28 DAY','14 DAY','21 DAY','7 DAY','RENTAL')
  70. AND (location_name ILIKE '%equipment%' OR location_name ILIKE '%adult 360%' OR location_name ILIKE '%adult ps2%');
  71.  
  72. UPDATE rogan.asset_copy SET book = FALSE WHERE serial = TRUE;
  73. UPDATE rogan.asset_copy SET book = FALSE WHERE video = TRUE;
  74. UPDATE rogan.asset_copy SET book = FALSE WHERE audio = TRUE;
  75.  
  76.  
  77. SELECT SUM(a.copy_id) AS "Books Total - F3", a.org2_shortname
  78. FROM (
  79.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  80.         FROM rogan.asset_copy COPY
  81.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  82.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  83.         WHERE COPY.deleted = FALSE AND date(COPY.create_date) <= '2015-06-30'
  84.         AND COPY.book = TRUE
  85.         GROUP BY 2
  86. UNION ALL
  87.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  88.         FROM rogan.asset_copy COPY
  89.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  90.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  91.         WHERE COPY.deleted = TRUE AND date(COPY.create_date) <= '2015-06-30'
  92.         and date(copy.edit_date) between '2014-07-01' and '2015-06-30'
  93.         AND COPY.book = TRUE
  94.         GROUP BY 2
  95. UNION ALL
  96.         SELECT COALESCE(COUNT(circ.id),0) AS copy_id, org2.shortname AS org2_shortname
  97.         FROM ACTION.non_cataloged_circulation circ
  98.         LEFT JOIN actor.org_unit org ON org.id = circ.circ_lib
  99.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  100.         WHERE date(circ.circ_time) between '2014-07-01' AND '2015-06-30'
  101.         GROUP BY 2
  102. ) a
  103. GROUP BY 2
  104. ORDER BY 2
  105. ;
  106.  
  107.  
  108. /*
  109. ------------------------------------------------------------------------------------------------------------------
  110. ------------------------------------------------------------------------------------------------------------------
  111. */
  112. SELECT SUM(a.copy_id) AS "Serials - F6", a.org2_shortname
  113. FROM (
  114.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  115.         FROM rogan.asset_copy COPY
  116.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  117.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  118.         WHERE COPY.deleted = FALSE AND date(COPY.create_date) <= '2015-06-30'
  119.         AND COPY.serial = TRUE
  120.         GROUP BY 2
  121. UNION ALL
  122.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  123.         FROM rogan.asset_copy COPY
  124.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  125.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  126.         WHERE COPY.deleted = TRUE AND date(COPY.create_date) <= '2015-06-30'
  127.         AND COPY.serial = TRUE
  128.         and date(copy.edit_date) between '2014-07-01' and '2015-06-30'
  129.         GROUP BY 2
  130. ) a
  131. GROUP BY 2
  132. ORDER BY 2
  133. ;
  134.  
  135.  
  136. /*
  137. ------------------------------------------------------------------------------------------------------------------
  138. ------------------------------------------------------------------------------------------------------------------
  139. */
  140. SELECT SUM(a.copy_id) AS "Audio - F9", a.org2_shortname
  141. FROM (
  142.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  143.         FROM rogan.asset_copy COPY
  144.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  145.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  146.         WHERE COPY.deleted = FALSE AND date(COPY.create_date) <= '2015-06-30'
  147.         AND COPY.audio = TRUE
  148.         GROUP BY 2
  149. UNION ALL
  150.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  151.         FROM rogan.asset_copy COPY
  152.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  153.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  154.         WHERE COPY.deleted = TRUE AND date(COPY.create_date) <= '2015-06-30'
  155.         AND date(COPY.edit_date) >= '2014-07-01' AND date(COPY.edit_date) <= '2015-06-30'
  156.         AND COPY.audio = TRUE
  157.         GROUP BY 2
  158. ) a
  159. GROUP BY 2
  160. ORDER BY 2
  161. ;
  162.  
  163.  
  164. /*
  165. total videos in collection at end of fiscal
  166. first search grabs undeleted items created on or before the cutoff date
  167. second search grabs items deleted during that year
  168. answers F12
  169. ------------------------------------------------------------------------------------------------------------------
  170. ------------------------------------------------------------------------------------------------------------------
  171. */
  172. SELECT SUM(a.copy_id) AS "Total Videos - F12", a.org2_shortname
  173. FROM (
  174.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  175.         FROM rogan.asset_copy COPY
  176.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  177.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  178.         WHERE COPY.deleted = FALSE AND date(COPY.create_date) <= '2015-06-30'
  179.         AND COPY.video = TRUE
  180.         GROUP BY 2
  181. UNION ALL
  182.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS copy_id, org2.shortname AS org2_shortname
  183.         FROM rogan.asset_copy COPY
  184.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  185.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  186.         WHERE COPY.deleted = TRUE AND date(COPY.create_date) <= '2015-06-30'
  187.         AND COPY.video = TRUE
  188.         and date(copy.edit_date) between '2014-07-01' and '2015-06-30'
  189.         GROUP BY 2
  190. ) a
  191. GROUP BY 2
  192. ORDER BY 2
  193. ;
  194.  
  195.  
  196. /*
  197. materials added within the fiscal year
  198. -------------------------------------- looks for a = language material, j = music, g = projected medium
  199. -------------------------------------- i = audio books are bundeled with j music as per SC requirements
  200. ------------------------------------------------------------------------------------------------------------------
  201. ------------------------------------------------------------------------------------------------------------------
  202. */
  203.  
  204. SELECT v.shortname AS "Library",
  205. COALESCE(SUM(t.books),0) AS "Books Added - F1", COALESCE(SUM(e.serials),0) AS "Serials Added - F4",
  206. COALESCE(SUM(s.sound),0) AS "Audios Added - F7", COALESCE(SUM(v.videos),0) AS "Videos Added - F10"
  207. FROM (
  208.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS videos, org2.shortname AS shortname
  209.         FROM rogan.asset_copy COPY
  210.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  211.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  212.         WHERE date(COPY.create_date) >= '2014-07-01' AND date(COPY.create_date) <= '2015-06-30'
  213.         AND COPY.video = TRUE
  214.         GROUP BY 2
  215. ) v
  216. LEFT JOIN (
  217.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS books, org2.shortname AS shortname
  218.         FROM rogan.asset_copy COPY
  219.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  220.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  221.         WHERE date(COPY.create_date) >= '2014-07-01' AND date(COPY.create_date) <= '2015-06-30'
  222.                 AND COPY.book = TRUE
  223.         GROUP BY 2
  224. ) t ON t.shortname = v.shortname
  225. LEFT JOIN (
  226.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS sound, org2.shortname AS shortname
  227.         FROM rogan.asset_copy COPY
  228.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  229.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  230.         WHERE date(COPY.create_date) >= '2014-07-01' AND date(COPY.create_date) <= '2015-06-30'
  231.                 AND COPY.audio = TRUE
  232.         GROUP BY 2
  233. ) s ON s.shortname = v.shortname
  234. LEFT JOIN (
  235.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS serials, org2.shortname AS shortname
  236.         FROM rogan.asset_copy COPY
  237.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  238.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  239.         WHERE date(COPY.create_date) >= '2014-07-01' AND date(COPY.create_date) <= '2015-06-30'
  240.                 AND COPY.serial = TRUE
  241.         GROUP BY 2
  242. ) e ON e.shortname = v.shortname
  243. GROUP BY 1
  244. ORDER BY 1
  245. ;
  246.  
  247.  
  248. /*
  249. materials weeded by end of fiscal - deleted or not
  250. -------------------------------------- looks for a = language material, j = music, g = projected medium
  251. -------------------------------------- i = audio books are bundeled with j music as per SC requirements
  252. ------------------------------------------------------------------------------------------------------------------
  253. ------------------------------------------------------------------------------------------------------------------
  254. */
  255.  
  256. SELECT v.shortname AS "Library",
  257. COALESCE(SUM(t.books),0) AS "Books Weeded - F2", COALESCE(SUM(e.serials),0) AS "Serials Weeded - F5 ",
  258. COALESCE(SUM(s.sound),0) AS "Audio Weeded - F8", COALESCE(SUM(v.videos),0) AS "Videos Weeded - F11"
  259. FROM (
  260.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS videos, org2.shortname AS shortname
  261.         FROM rogan.asset_copy COPY
  262.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  263.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  264.         WHERE COPY.deleted = TRUE AND date(COPY.edit_date) >= '2014-07-01' AND date(COPY.edit_date) <= '2015-06-30'
  265.                 AND COPY.video = TRUE
  266.         GROUP BY 2
  267. ) v
  268. LEFT JOIN (
  269.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS books, org2.shortname AS shortname
  270.         FROM rogan.asset_copy COPY
  271.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  272.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  273.         WHERE COPY.deleted = TRUE AND date(COPY.edit_date) >= '2014-07-01' AND date(COPY.edit_date) <= '2015-06-30'
  274.                 AND COPY.book = TRUE
  275.         GROUP BY 2
  276. ) t ON t.shortname = v.shortname
  277. LEFT JOIN (
  278.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS sound, org2.shortname AS shortname
  279.         FROM rogan.asset_copy COPY
  280.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  281.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  282.         WHERE COPY.deleted = TRUE AND date(COPY.edit_date) >= '2014-07-01' AND date(COPY.edit_date) <= '2015-06-30'
  283.                 AND COPY.audio = TRUE
  284.         GROUP BY 2
  285. ) s ON s.shortname = v.shortname
  286. LEFT JOIN (
  287.         SELECT COALESCE(COUNT(DISTINCT COPY.id),0) AS serials, org2.shortname AS shortname
  288.         FROM rogan.asset_copy COPY
  289.         JOIN actor.org_unit org ON org.id = COPY.circ_lib
  290.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  291.         WHERE COPY.deleted = TRUE AND date(COPY.edit_date) >= '2014-07-01' AND date(COPY.edit_date) <= '2015-06-30'
  292.                 AND COPY.serial = TRUE
  293.         GROUP BY 2
  294. ) e ON e.shortname = v.shortname
  295. GROUP BY 1
  296. ORDER BY 1
  297. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement