Advertisement
roganhamby

Annual State Statistics - old

Oct 8th, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- SCLENDS is part of a consortium and this assumes that the library recorded in action.circulation.circ_lib
  2. -- should get the credit for the circulation
  3.  
  4.  
  5. /*
  6. total videos in collection at end of fiscal - deleted or not
  7. ------------------------------------------------------------------------------------------------------------------
  8. ------------------------------------------------------------------------------------------------------------------
  9. */
  10. select sum(a.copy_id) as "Videos", a.org2_shortname
  11. from (
  12.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  13.     from asset.copy copy
  14.     join actor.org_unit org on org.id = copy.circ_lib
  15.     join actor.org_unit org2 on org2.id = org.parent_ou
  16.     join asset.call_number acn on acn.id = copy.call_number
  17.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  18.     where copy.deleted = FALSE and date(copy.create_date) <= '2013-06-30'
  19.     and meta.tag = 'LDR' and substring(meta.value from 7 for 1) = 'g'
  20.     group by 2
  21. UNION ALL
  22.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  23.     from asset.copy copy
  24.     join actor.org_unit org on org.id = copy.circ_lib
  25.     join actor.org_unit org2 on org2.id = org.parent_ou
  26.     join asset.call_number acn on acn.id = copy.call_number
  27.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  28.     where copy.deleted = TRUE and date(copy.create_date) <= '2013-06-30'
  29.     and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  30.     and meta.tag = 'LDR' and substring(meta.value from 7 for 1) = 'g'
  31.     group by 2
  32. ) a
  33. group by 2
  34. order by 2
  35. ;
  36.  
  37.  
  38. /*
  39. total language mateerials (aka books) in collection at end of fiscal - deleted or not
  40. ------------------------------------------------------------------------------------------------------------------
  41. ------------------------------------------------------------------------------------------------------------------
  42. */
  43.  
  44.  
  45. select sum(a.copy_id) as "Books", a.org2_shortname
  46. from (
  47.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  48.     from asset.copy copy
  49.     join actor.org_unit org on org.id = copy.circ_lib
  50.     join actor.org_unit org2 on org2.id = org.parent_ou
  51.     join asset.call_number acn on acn.id = copy.call_number
  52.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  53.     where copy.deleted = FALSE and date(copy.create_date) <= '2013-06-30'
  54.     and meta.tag = 'LDR' and substring(meta.value from 7 for 1) = 'a'
  55.     group by 2
  56. UNION ALL
  57.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  58.     from asset.copy copy
  59.     join actor.org_unit org on org.id = copy.circ_lib
  60.     join actor.org_unit org2 on org2.id = org.parent_ou
  61.     join asset.call_number acn on acn.id = copy.call_number
  62.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  63.     where copy.deleted = TRUE and date(copy.create_date) <= '2013-06-30'
  64.     and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  65.     and meta.tag = 'LDR' and substring(meta.value from 7 for 1) = 'a'
  66.     group by 2
  67. ) a
  68. group by 2
  69. order by 2
  70. ;
  71.  
  72.  
  73. /*
  74. total j = music and i = audio books  in collection at end of fiscal - deleted or not
  75. ------------------------------------------------------------------------------------------------------------------
  76. ------------------------------------------------------------------------------------------------------------------
  77. */
  78. select sum(a.copy_id) as "Audio", a.org2_shortname
  79. from (
  80.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  81.     from asset.copy copy
  82.     join actor.org_unit org on org.id = copy.circ_lib
  83.     join actor.org_unit org2 on org2.id = org.parent_ou
  84.     join asset.call_number acn on acn.id = copy.call_number
  85.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  86.     where copy.deleted = FALSE and date(copy.create_date) <= '2013-06-30'
  87.     and meta.tag = 'LDR' and (substring(meta.value from 7 for 1) = 'j' or substring(meta.value from 7 for 1) = 'i')
  88.     group by 2
  89. UNION ALL
  90.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  91.     from asset.copy copy
  92.     join actor.org_unit org on org.id = copy.circ_lib
  93.     join actor.org_unit org2 on org2.id = org.parent_ou
  94.     join asset.call_number acn on acn.id = copy.call_number
  95.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  96.     where copy.deleted = TRUE and date(copy.create_date) <= '2013-06-30'
  97.     and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  98.     and meta.tag = 'LDR' and (substring(meta.value from 7 for 1) = 'j' or substring(meta.value from 7 for 1) = 'i')
  99.     group by 2
  100. ) a
  101. group by 2
  102. order by 2
  103. ;
  104.  
  105.  
  106. /*
  107. total mateirals in collection at end of fiscal - deleted or not, broken down by marc record type
  108. ------------------------------------------------------------------------------------------------------------------
  109. ------------------------------------------------------------------------------------------------------------------
  110. */
  111.  
  112. select sum(a.copy_id) as "Other", a.org2_shortname
  113. from (
  114.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  115.     from 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.     join asset.call_number acn on acn.id = copy.call_number
  119.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  120.     where copy.deleted = FALSE and date(copy.create_date) <= '2013-06-30'
  121.     and meta.tag = 'LDR' and substring(meta.value from 7 for 1) in ('c','d','e','f','k','m','o','p','r','t')
  122.     group by 2
  123. UNION ALL
  124.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  125.     from asset.copy copy
  126.     join actor.org_unit org on org.id = copy.circ_lib
  127.     join actor.org_unit org2 on org2.id = org.parent_ou
  128.     join asset.call_number acn on acn.id = copy.call_number
  129.     left outer join metabib.real_full_rec meta on meta.record = acn.record
  130.     where copy.deleted = TRUE and date(copy.create_date) <= '2013-06-30'
  131.     and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  132.     and meta.tag = 'LDR' and substring(meta.value from 7 for 1) in ('c','d','e','f','k','m','o','p','r','t')
  133.     group by 2
  134. ) a
  135. group by 2
  136. order by 2
  137. ;
  138.  
  139. /*
  140. materials added within the fiscal year
  141. -------------------------------------- looks for a = language material, j = music, g = projected medium
  142. -------------------------------------- i = audio books are bundeled with j music as per SC requirements
  143. ------------------------------------------------------------------------------------------------------------------
  144. ------------------------------------------------------------------------------------------------------------------
  145. */
  146.  
  147. select sum(t.books) as "Books", sum(s.sound) as "Audios", sum(v.videos) as "Videos",
  148. sum(o.other) as "Others", v.shortname as "Library"
  149. from (
  150.     select count(copy.id) as videos, org2.shortname as shortname
  151.     from 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.     join asset.call_number call on call.id = copy.call_number
  155.     left outer join metabib.real_full_rec meta on meta.record = call.record
  156.     where date(copy.create_date) >= '2012-07-01' and date(copy.create_date) <= '2013-06-30'
  157.     and meta.tag = 'LDR'
  158.     and substring(meta.value from 7 for 1) = 'g'
  159.     group by 2
  160. ) v
  161. join (
  162.     select count(copy.id) as books, org2.shortname as shortname
  163.     from asset.copy copy
  164.     join actor.org_unit org on org.id = copy.circ_lib
  165.     join actor.org_unit org2 on org2.id = org.parent_ou
  166.     join asset.call_number call on call.id = copy.call_number
  167.     left outer join metabib.real_full_rec meta on meta.record = call.record
  168.     where date(copy.create_date) >= '2012-07-01' and date(copy.create_date) <= '2013-06-30'
  169.     and meta.tag = 'LDR'
  170.     and substring(meta.value from 7 for 1) = 'a'
  171.     group by 2
  172. ) t on t.shortname = v.shortname
  173. join (
  174.     select count(copy.id) as sound, org2.shortname as shortname
  175.     from 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.     join asset.call_number call on call.id = copy.call_number
  179.     left outer join metabib.real_full_rec meta on meta.record = call.record
  180.     where date(copy.create_date) >= '2012-07-01' and date(copy.create_date) <= '2013-06-30'
  181.     and meta.tag = 'LDR'
  182.     and substring(meta.value from 7 for 1) in ('i','j')
  183.     group by 2
  184. ) s on s.shortname = v.shortname
  185. join (
  186.     select count(copy.id) as other, org2.shortname as shortname
  187.     from asset.copy copy
  188.     join actor.org_unit org on org.id = copy.circ_lib
  189.     join actor.org_unit org2 on org2.id = org.parent_ou
  190.     join asset.call_number call on call.id = copy.call_number
  191.     left outer join metabib.real_full_rec meta on meta.record = call.record
  192.     where date(copy.create_date) >= '2012-07-01' and date(copy.create_date) <= '2013-06-30'
  193.     and meta.tag = 'LDR'
  194.     and substring(meta.value from 7 for 1) in ('c','d','e','f','k','m','o','p','r','t')
  195.     group by 2
  196. ) o on o.shortname = v.shortname
  197. group by 5
  198. order by 5
  199. ;
  200.  
  201. /*
  202. materials added by end of fiscal - deleted or not
  203. -------------------------------------- looks for a = language material, j = music, g = projected medium
  204. -------------------------------------- i = audio books are bundeled with j music as per SC requirements
  205. ------------------------------------------------------------------------------------------------------------------
  206. ------------------------------------------------------------------------------------------------------------------
  207. */
  208.  
  209. select sum(t.books) as "Books Weeded", sum(s.sound) as "Audio Weeded", sum(v.videos) as "Videos Weeded",
  210. sum(o.other) as "Other Weeded", v.shortname as "Library"
  211. from (
  212.     select count(copy.id) as videos, org2.shortname as shortname
  213.     from asset.copy copy
  214.     join actor.org_unit org on org.id = copy.circ_lib
  215.     join actor.org_unit org2 on org2.id = org.parent_ou
  216.     join asset.call_number call on call.id = copy.call_number
  217.     left outer join metabib.real_full_rec meta on meta.record = call.record
  218.     where copy.deleted = TRUE and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  219.     and meta.tag = 'LDR'
  220.     and substring(meta.value from 7 for 1) = 'g'
  221.     group by 2
  222. ) v
  223. join (
  224.     select count(copy.id) as books, org2.shortname as shortname
  225.     from asset.copy copy
  226.     join actor.org_unit org on org.id = copy.circ_lib
  227.     join actor.org_unit org2 on org2.id = org.parent_ou
  228.     join asset.call_number call on call.id = copy.call_number
  229.     left outer join metabib.real_full_rec meta on meta.record = call.record
  230.     where copy.deleted = TRUE and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  231.     and meta.tag = 'LDR'
  232.     and substring(meta.value from 7 for 1) = 'a'
  233.     group by 2
  234. ) t on t.shortname = v.shortname
  235. join (
  236.     select count(copy.id) as sound, org2.shortname as shortname
  237.     from asset.copy copy
  238.     join actor.org_unit org on org.id = copy.circ_lib
  239.     join actor.org_unit org2 on org2.id = org.parent_ou
  240.     join asset.call_number call on call.id = copy.call_number
  241.     left outer join metabib.real_full_rec meta on meta.record = call.record
  242.     where copy.deleted = TRUE and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  243.     and meta.tag = 'LDR'
  244.     and substring(meta.value from 7 for 1) in ('i','j')
  245.     group by 2
  246. ) s on s.shortname = v.shortname
  247. join (
  248.     select count(copy.id) as other, org2.shortname as shortname
  249.     from asset.copy copy
  250.     join actor.org_unit org on org.id = copy.circ_lib
  251.     join actor.org_unit org2 on org2.id = org.parent_ou
  252.     join asset.call_number call on call.id = copy.call_number
  253.     left outer join metabib.real_full_rec meta on meta.record = call.record
  254.     where copy.deleted = TRUE and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  255.     and meta.tag = 'LDR'
  256.     and substring(meta.value from 7 for 1) in ('c','d','e','f','k','m','o','p','r','t')
  257.     group by 2
  258. ) o on o.shortname = v.shortname
  259. group by 5
  260. order by 5
  261. ;
  262.  
  263. /*
  264. counts patron accounts under the age of 18 by the end of the fiscal year where the age is blank due to the dob
  265. being null because we used to allow that.  we look to see if the account is labeled as teen, juvenile, youth or child.
  266. (254,259,145,146,147,148,165,166,167,168,171,172,173,174,207,215,226,193,194,195,189,190,191,192,270,271,240,241)
  267. I check for dob first becuase it could be an adult in a child account but I assume if the dob is null that it is on the
  268. exception list above and a child, I look to see if it's marked deleted and if it was marked past the cut off
  269. and if it was created in the last three years
  270.  
  271. NOTES: patron profile consolidation will affect this as will the usr activity tracking
  272. */
  273.  
  274. -- all accounts for checking against
  275.  
  276. select count(usr.id) as "Patrons", org2.shortname
  277. from actor.usr usr
  278. join actor.org_unit org on org.id = usr.home_ou
  279. join actor.org_unit org2 on org2.id = org.parent_ou
  280. where
  281. usr.deleted = FALSE
  282. and
  283. ( date(usr.expire_date) >= '2010-07-01' or date(usr.create_date) >= '2010-07-01' )
  284. group by 2
  285. order by 2
  286. ;
  287. /* juvenile accounts, technically it would be better to update via a last update and get those fixed than usr.create but there are so few, it doesn't matter */
  288.  
  289. select count(usr.id) as "Juveniles", org2.shortname
  290. from actor.usr usr
  291. join actor.org_unit org on org.id = usr.home_ou
  292. join actor.org_unit org2 on org2.id = org.parent_ou
  293. where
  294. (
  295.     date(usr.create_date) >= '2010-07-01'
  296.     or  
  297.     (
  298.         usr.deleted = FALSE
  299.         and
  300.         date(usr.expire_date) >= '2010-07-01'
  301.     )
  302. )
  303. and
  304.     (
  305.         date(usr.dob) >= date('1995-07-01')
  306.         or
  307.         (dob is null and usr.profile in (254,259,145,146,147,148,165,166,167,168,171,172,173,174,207,215,226,193,194,195,189,190,191,192,270,271,240,241))
  308.     )
  309. group by 2
  310. order by 2
  311. ;
  312.  
  313.  
  314. -- adult patrons, basically inverse of above
  315.  
  316. select count(usr.id) as "Adults", org2.shortname
  317. from actor.usr usr
  318. join actor.org_unit org on org.id = usr.home_ou
  319. join actor.org_unit org2 on org2.id = org.parent_ou
  320. where
  321. (
  322.     date(usr.create_date) >= '2010-07-01'
  323.     or  
  324.     (
  325.         usr.deleted = FALSE
  326.         and
  327.         date(usr.expire_date) >= '2010-07-01'
  328.     )
  329. )
  330. and
  331.     (
  332.         date(usr.dob) <= date('1995-07-01')
  333.         or
  334.         (dob is null and usr.profile not in (254,259,145,146,147,148,165,166,167,168,171,172,173,174,207,215,226,193,194,195,189,190,191,192,270,271,240,241))
  335.     )
  336. group by 2
  337. order by 2
  338. ;
  339.  
  340.  
  341. -------------------------------------- circ by org units
  342. ------------------------------------------------------------------------------------------------------------------
  343. ------------------------------------------------------------------------------------------------------------------
  344.  
  345.  
  346. select circ_cat.shortname, circ_cat.circs + circ_non.circs
  347. from
  348.     (   select count(circ.id) as circs, org2.shortname
  349.         from action.circulation circ
  350.         join actor.org_unit org on org.id = circ.circ_lib
  351.         join actor.org_unit org2 on org2.id = org.parent_ou
  352.         where date(circ.xact_start) >= '2012-07-01' and date(circ.xact_start) <= '2013-06-30'
  353.         group by 2
  354.     ) circ_cat
  355. join (  select count(circ.id) as circs, org2.shortname
  356.         from action.non_cataloged_circulation circ
  357.         join actor.org_unit org on org.id = circ.circ_lib
  358.         join actor.org_unit org2 on org2.id = org.parent_ou
  359.         where date(circ.circ_time) >= '2012-07-01' and date(circ.circ_time) <= '2013-06-30'
  360.         group by 2
  361.     ) circ_non on circ_non.shortname = circ_cat.shortname
  362. order by 1 asc;
  363.  
  364.  
  365.  
  366. -------------------------------------- circ by material format from leader
  367. -------------------------------------- looks for a = language material, j = music, g = projected medium
  368. -------------------------------------- i = audio books, do they go into an 'audio' or a 'book' category?
  369. -------------------------------------- and other
  370. -------------------------------------- for non-cat circs they're all added to language materials
  371. ------------------------------------------------------------------------------------------------------------------
  372. ------------------------------------------------------------------------------------------------------------------
  373. SELECT SUM(t.text_circs) AS "Book Circs", SUM(s.sound_circs)+SUM(ab.audiobook_circs) AS "Sound Circs", SUM(v.video_circs) AS "Video Circs",
  374. SUM(o.other_circs) AS "Other Circs", v.shortname AS "Library"
  375. FROM (
  376.         SELECT COUNT(circ.id) AS video_circs, org2.shortname AS shortname
  377.         FROM ACTION.circulation circ
  378.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  379.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  380.         JOIN asset.COPY COPY ON COPY.id = circ.target_copy
  381.         JOIN asset.call_number call ON call.id = COPY.call_number
  382.         LEFT OUTER JOIN metabib.real_full_rec meta ON meta.record = call.record
  383.         WHERE date(circ.xact_start) >= '2012-07-01' AND date(circ.xact_start) <= '2013-06-30'
  384.         AND meta.tag = 'LDR'
  385.         AND SUBSTRING(meta.VALUE FROM 7 FOR 1) = 'g'
  386.         GROUP BY 2
  387. ) v
  388. JOIN (
  389.         SELECT circ_cat.shortname as shortname, (circ_cat.circs + circ_non.circs) as text_circs
  390.         FROM
  391.         (      
  392.                 SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  393.                 FROM ACTION.circulation circ
  394.                 JOIN actor.org_unit org ON org.id = circ.circ_lib
  395.                 JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  396.                 JOIN asset.COPY COPY ON COPY.id = circ.target_copy
  397.                 JOIN asset.call_number call ON call.id = COPY.call_number
  398.                 LEFT JOIN metabib.real_full_rec meta ON meta.record = call.record
  399.                 WHERE date(circ.xact_start) >= '2012-07-01' AND date(circ.xact_start) <= '2013-06-30'
  400.                 AND meta.tag = 'LDR'
  401.                 AND SUBSTRING(meta.VALUE FROM 7 FOR 1) = 'a'
  402.                 GROUP BY 2      
  403.         ) circ_cat
  404.         JOIN
  405.         (       SELECT COUNT(circ.id) AS circs, org2.shortname
  406.                 FROM ACTION.non_cataloged_circulation circ
  407.                 JOIN actor.org_unit org ON org.id = circ.circ_lib
  408.                 JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  409.                 WHERE date(circ.circ_time) >= '2012-07-01' AND date(circ.circ_time) <= '2013-06-30'
  410.                 GROUP BY 2
  411.         ) circ_non ON circ_non.shortname = circ_cat.shortname
  412. ) t ON t.shortname = v.shortname
  413. JOIN (
  414.         SELECT COUNT(circ.id) AS sound_circs, org2.shortname AS shortname
  415.         FROM ACTION.circulation circ
  416.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  417.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  418.         JOIN asset.COPY COPY ON COPY.id = circ.target_copy
  419.         JOIN asset.call_number call ON call.id = COPY.call_number
  420.         LEFT JOIN metabib.real_full_rec meta ON meta.record = call.record
  421.         WHERE date(circ.xact_start) >= '2012-07-01' AND date(circ.xact_start) <= '2013-06-30'
  422.         AND meta.tag = 'LDR'
  423.         AND SUBSTRING(meta.VALUE FROM 7 FOR 1) = 'j'
  424.         GROUP BY 2
  425. ) s ON s.shortname = v.shortname
  426. JOIN (
  427.         SELECT COUNT(circ.id) AS audiobook_circs, org2.shortname AS shortname
  428.         FROM ACTION.circulation circ
  429.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  430.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  431.         JOIN asset.COPY COPY ON COPY.id = circ.target_copy
  432.         JOIN asset.call_number call ON call.id = COPY.call_number
  433.         LEFT JOIN metabib.real_full_rec meta ON meta.record = call.record
  434.         WHERE date(circ.xact_start) >= '2012-07-01' AND date(circ.xact_start) <= '2013-06-30'
  435.         AND meta.tag = 'LDR'
  436.         AND SUBSTRING(meta.VALUE FROM 7 FOR 1) = 'i'
  437.         GROUP BY 2
  438. ) ab ON ab.shortname = v.shortname
  439. JOIN (
  440.         SELECT COUNT(circ.id) AS other_circs, org2.shortname AS shortname
  441.         FROM ACTION.circulation circ
  442.         JOIN actor.org_unit org ON org.id = circ.circ_lib
  443.         JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  444.         JOIN asset.COPY COPY ON COPY.id = circ.target_copy
  445.         JOIN asset.call_number call ON call.id = COPY.call_number
  446.         LEFT JOIN metabib.real_full_rec meta ON meta.record = call.record
  447.         WHERE date(circ.xact_start) >= '2012-07-01' AND date(circ.xact_start) <= '2013-06-30'
  448.         AND meta.tag = 'LDR'
  449.         AND SUBSTRING(meta.VALUE FROM 7 FOR 1) IN ('c','d','e','f','k','m','o','p','r','t')
  450.         GROUP BY 2
  451. ) o ON o.shortname = v.shortname
  452. GROUP BY 5
  453. ORDER BY 5
  454. ;
  455.  
  456.  
  457. -------------------------------------- circ by audience drawn from copy location
  458. -------------------------------------- adults get the non cat circs
  459. ------------------------------------------------------------------------------------------------------------------
  460. ------------------------------------------------------------------------------------------------------------------
  461.  
  462.  
  463. select sum(a.adult_circs) as "Adult Circs", sum(y.young_circs) as "Young Adult Circs", sum(j.juv_circs) as "Juvenile Circs",
  464. sum(o.other_circs) as "Other Circs", a.org2_shortname as "Library"
  465. from
  466. (
  467.         SELECT circ_cat.shortname as org2_shortname, (circ_cat.circs + circ_non.circs) as adult_circs
  468.         FROM
  469.         (      
  470.             select count(circ.id) as circs, org2.shortname as shortname
  471.             from action.circulation circ
  472.             join actor.org_unit org on org.id = circ.circ_lib
  473.             join actor.org_unit org2 on org2.id = org.parent_ou
  474.             join asset.copy_location loc on loc.id = circ.copy_location
  475.             where date(circ.xact_start) >= '2012-07-01' and date(circ.xact_start) <= '2013-06-30'
  476.             and loc.name like 'Adu%'
  477.             group by 2
  478.          ) circ_cat
  479.         JOIN
  480.         (   SELECT COUNT(circ.id) AS circs, org2.shortname
  481.             FROM ACTION.non_cataloged_circulation circ
  482.             JOIN actor.org_unit org ON org.id = circ.circ_lib
  483.             JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  484.             WHERE date(circ.circ_time) >= '2012-07-01' AND date(circ.circ_time) <= '2013-06-30'
  485.             GROUP BY 2
  486.         ) circ_non ON circ_non.shortname = circ_cat.shortname
  487. ) a
  488. join (
  489.     select count(circ.id) as young_circs, org2.shortname as org2_shortname
  490.     from action.circulation circ
  491.     join actor.org_unit org on org.id = circ.circ_lib
  492.     left join actor.org_unit org2 on org2.id = org.parent_ou
  493.     join asset.copy_location loc on loc.id = circ.copy_location
  494.     where date(circ.xact_start) >= '2012-07-01' and date(circ.xact_start) <= '2013-06-30'
  495.     and loc.name like 'You%'
  496.     group by 2
  497. ) y on y.org2_shortname = a.org2_shortname
  498. join (
  499.     select count(circ.id) as juv_circs, org2.shortname as org2_shortname
  500.     from action.circulation circ
  501.     join actor.org_unit org on org.id = circ.circ_lib
  502.     join actor.org_unit org2 on org2.id = org.parent_ou
  503.     join asset.copy_location loc on loc.id = circ.copy_location
  504.     where date(circ.xact_start) >= '2012-07-01' and date(circ.xact_start) <= '2013-06-30'
  505.     and loc.name like 'Juv%'
  506.     group by 2
  507. ) j on j.org2_shortname = a.org2_shortname
  508. join (
  509.     select count(circ.id) as other_circs, org2.shortname as org2_shortname
  510.     from action.circulation circ
  511.     join actor.org_unit org on org.id = circ.circ_lib
  512.     join actor.org_unit org2 on org2.id = org.parent_ou
  513.     join asset.copy_location loc on loc.id = circ.copy_location
  514.     where date(circ.xact_start) >= '2012-07-01' and date(circ.xact_start) <= '2013-06-30'
  515.     and loc.name not like 'Adu%' and loc.name not like 'Juv%' and loc.name not like 'You%'
  516.     group by 2
  517. ) o on o.org2_shortname = a.org2_shortname
  518. group by 5
  519. order by 5
  520. ;
  521.  
  522.  
  523.  
  524.  
  525. -------------------------------------- total items in collection as of end of fiscal year, deleted and not
  526. ------------------------------------------------------------------------------------------------------------------
  527. ------------------------------------------------------------------------------------------------------------------
  528.  
  529. select sum(a.copy_id), a.org2_shortname
  530. from (
  531.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  532.     from asset.copy copy
  533.     join actor.org_unit org on org.id = copy.circ_lib
  534.     join actor.org_unit org2 on org2.id = org.parent_ou
  535.     where copy.deleted = FALSE and date(copy.create_date) <= '2013-06-30'
  536.     group by 2
  537. UNION ALL
  538.     select count(copy.id) as copy_id, org2.shortname as org2_shortname
  539.     from asset.copy copy
  540.     join actor.org_unit org on org.id = copy.circ_lib
  541.     join actor.org_unit org2 on org2.id = org.parent_ou
  542.     where copy.deleted = TRUE and date(copy.create_date) <= '2013-06-30'
  543.     and date(copy.edit_date) >= '2012-07-01' and date(copy.edit_date) <= '2013-06-30'
  544.     group by 2
  545. ) a
  546. group by 2
  547. order by 2
  548. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement