SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | Section G: LIBRARY USERS, VISITS, COMPUTER AND INTERNET | |
3 | ||
4 | Registered Users | |
5 | G1 Adult__________________________ | |
6 | G2 Juvenile__________________________ | |
7 | G3 TOTAL (G1 + G2)__________________________ | |
8 | ||
9 | counts patron accounts under the age of 18 by the end of the fiscal year where the age is blank due to the dob | |
10 | being null because we used to allow that. we look to see if the account is labeled as juvenile in the description, | |
11 | this will change after the Fall 2015 profile consolidaiton and we should be able to do it more cleanly off | |
12 | pgt.name | |
13 | ||
14 | 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 | |
15 | exception list above and a child, I look to see if it's marked deleted and if it was marked past the cut off | |
16 | and if it was created in the last three years | |
17 | ||
18 | */ | |
19 | ||
20 | select a.library as "Library", a.adults as "Adults - G1", j.juveniles as "Juveniles - G2", a.adults+j.juveniles as "Total - G3" | |
21 | from ( | |
22 | SELECT org2.shortname as "library", COUNT(usr.id) AS "adults" | |
23 | FROM actor.usr usr | |
24 | JOIN actor.org_unit org ON org.id = usr.home_ou | |
25 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
26 | join permission.grp_tree pgt on pgt.id = usr.profile | |
27 | WHERE | |
28 | ( | |
29 | date(usr.create_date) >= '2012-07-01' | |
30 | OR | |
31 | ( | |
32 | usr.deleted = FALSE | |
33 | AND | |
34 | date(usr.expire_date) >= '2012-07-01' | |
35 | ) | |
36 | ) | |
37 | AND | |
38 | ( | |
39 | date(usr.dob) <= date('1997-07-01') | |
40 | OR | |
41 | (dob IS NULL AND pgt.description not ilike '%juv%') | |
42 | ) | |
43 | GROUP BY 1 | |
44 | ORDER BY 1 | |
45 | ) a | |
46 | join ( | |
47 | SELECT org2.shortname as "library", COUNT(usr.id) AS "juveniles" | |
48 | FROM actor.usr usr | |
49 | JOIN actor.org_unit org ON org.id = usr.home_ou | |
50 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
51 | join permission.grp_tree pgt on pgt.id = usr.profile | |
52 | WHERE | |
53 | ( | |
54 | date(usr.create_date) >= '2012-07-01' | |
55 | OR | |
56 | ( | |
57 | usr.deleted = FALSE | |
58 | AND | |
59 | date(usr.expire_date) >= '2012-07-01' | |
60 | ) | |
61 | ) | |
62 | AND | |
63 | ( | |
64 | date(usr.dob) >= date('1997-07-01') | |
65 | OR | |
66 | -- next year after next round we should be able to do this more cleanly off pgt.name | |
67 | (dob IS NULL AND pgt.description ilike '%juv%') | |
68 | ) | |
69 | GROUP BY 1 | |
70 | ORDER BY 1 | |
71 | ) j on j.library = a.library; | |
72 | ||
73 | ||
74 | ||
75 | /* | |
76 | ||
77 | ||
78 | Section H: REFERENCE, CIRCULATION | |
79 | ||
80 | Circulation Transactions and Interlibrary Loan H2 - H11 (In all sections, if no circulation to report, enter 0) | |
81 | Juvenile Circulation (may include Teen/YA circulation per library policy) | |
82 | H2 Print__________________________ | |
83 | H3 Non-Print (not books or electronic/downloadable items)__________________________ | |
84 | H4 TOTAL JUVENILE CIRCULATION (H2 + H3)__________________________ | |
85 | ||
86 | Adult Circulation (may include Teen/YA circulation per library policy) | |
87 | H5 Print__________________________ | |
88 | H6 Non-Print (not books or electronic/downloadable items)__________________________ | |
89 | H7 TOTAL (H5 + H6)__________________________ | |
90 | ||
91 | */ | |
92 | ||
93 | - | -------------------------------------- circ by material format from circ mod and shelving location |
93 | + | -------------------------------------- circ by material format from leader and audience |
94 | -------------------------------------- looks for a = language material = book | |
95 | -------------------------------------- i = audio books, j = music, g = projected medium aka 'not a' = non-print | |
96 | -------------------------------------- non-cat circs are all added to print materials | |
97 | ------------------------------------------------------------------------------------------------------------------ | |
98 | ------------------------------------------------------------------------------------------------------------------ | |
99 | - | /* create a table and map per circulation */ |
99 | + | |
100 | drop table if exists rogan.action_circulation; | |
101 | drop table if exists rogan.circ_ldrs; | |
102 | - | select * from action.circulation where date(create_time) between '2014-07-01' and '2015-06-30'; |
102 | + | |
103 | create table rogan.action_circulation as | |
104 | - | alter table rogan.action_circulation add column print boolean default TRUE; |
104 | + | select * from action.circulation circ |
105 | WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30'; | |
106 | - | /* map print = true based on these circ mods */ |
106 | + | |
107 | create table rogan.circ_ldrs as | |
108 | - | update rogan.action_circulation set print = false where target_copy in ( |
108 | + | SELECT circ.id as "circ_id", SUBSTRING(meta.VALUE FROM 7 FOR 1) as "circ_ldr" |
109 | - | select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id |
109 | + | FROM rogan.action_circulation circ |
110 | - | where ac.circ_modifier in ('ELECTRONIC EQUIPMENT','VIDEO','AUDIO','EREADER','PLAYAWAY','AUDIO BOOK', |
110 | + | JOIN asset.copy copy ON copy.id = circ.target_copy |
111 | - | 'THEME KIT','EQUIPMENT','KIT','INTERNET','GAME','LEASE DVD') |
111 | + | JOIN asset.call_number call ON call.id = copy.call_number |
112 | - | ); |
112 | + | LEFT OUTER JOIN metabib.real_full_rec meta ON meta.record = call.record |
113 | AND meta.tag = 'LDR' | |
114 | - | /* then it got a lot more manual looking at shelving locations. I made a review of a sample of five thousand shelving |
114 | + | |
115 | - | location entries and based on that assumed that copies with shelving locations saying AUDIO or VIDEO or EQUIPMENT |
115 | + | |
116 | - | should be changed to non-print then I re-ran it with exclusions and found more like DVD */ |
116 | + | |
117 | juv_a.circs as "Juvenile Print Circs - H2", juv_not_a.circs as "Juvenile Non-Print Circs - H3", | |
118 | - | update rogan.action_circulation set print = false where target_copy in ( |
118 | + | juv_a.circs+juv_not_a.circs+coalesce(non.circs,0) as "Total Juvenile Circs - H4", |
119 | - | select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id |
119 | + | adult_a.circs as "Adult Print Circs - H5", adult_not_a.circs as "Adult Non-Print Circs - H6", |
120 | - | join asset.copy_location acl on acl.id = ac.location |
120 | + | |
121 | - | where ac.circ_modifier in ('ELECTRONIC EQUIPMENT','VIDEO','AUDIO','EREADER','PLAYAWAY','AUDIO BOOK', |
121 | + | |
122 | - | 'THEME KIT','EQUIPMENT','KIT','INTERNET','GAME','LEASE DVD') |
122 | + | |
123 | - | and (acl.name ilike '%audio%' or acl.name ilike '%video%' or acl.name ilike '%equipment%' or acl.name ilike '%dvd%' |
123 | + | |
124 | - | or acl.name ilike '%books on cd%' or acl.name ilike '%books on cassette%' or acl.name ilike '%music cd%' or |
124 | + | |
125 | - | acl.name ilike '%adult 360%' or acl.name ilike '%adult ps2%') |
125 | + | |
126 | - | ); |
126 | + | JOIN asset.copy copy ON copy.id = circ.target_copy |
127 | JOIN asset.call_number call ON call.id = copy.call_number | |
128 | - | /* now I will go through all distinct occurances of the library systems and these circ mods with other shelving |
128 | + | join asset.copy_location acl on acl.id = copy.location |
129 | - | location names excluding those that had audio, video or unknown in the name */ |
129 | + | LEFT OUTER JOIN rogan.circ_ldrs ldrs ON ldrs.circ_id = circ.id |
130 | WHERE ldrs.circ_ldr = 'a' | |
131 | - | select DISTINCT aou.parent_ou, ac.circ_modifier, acl.name |
131 | + | and ( acl.name ilike '%juv%' or acl.name ilike '%young%' ) |
132 | - | from asset.copy ac |
132 | + | |
133 | - | join actor.org_unit aou on aou.id = ac.circ_lib |
133 | + | |
134 | - | join asset.copy_location acl on acl.id = ac.location |
134 | + | |
135 | - | where ac.circ_modifier in ('21 DAY LEASE','14 DAY LEASE','7 DAY LEASE','28 DAY','14 DAY','21 DAY','7 DAY','RENTAL') |
135 | + | |
136 | - | and acl.name not ilike '%audio%' and acl.name not ilike '%audio%' and acl.name not ilike '%video%' |
136 | + | |
137 | - | and acl.name not ilike '%equipment%' and acl.name not ilike '%dvd%' and acl.name not ilike '%books on cd%' |
137 | + | |
138 | - | and acl.name not ilike '%books on cassette%' and acl.name not ilike '%music cd%' and |
138 | + | |
139 | - | acl.name not ilike '%adult 360%' and acl.name not ilike '%adult ps2%' |
139 | + | JOIN asset.copy copy ON copy.id = circ.target_copy |
140 | - | order by 1, 2; |
140 | + | JOIN asset.call_number call ON call.id = copy.call_number |
141 | join asset.copy_location acl on acl.id = copy.location | |
142 | - | alter table rogan.action_circulation add column adult boolean default true; |
142 | + | LEFT OUTER JOIN rogan.circ_ldrs ldrs ON ldrs.circ_id = circ.id |
143 | WHERE ldrs.circ_ldr = 'a' | |
144 | - | update rogan.action_circulation set adult = false where target_copy in ( |
144 | + | and ( acl.name not ilike '%juv%' or acl.name not ilike '%young%' ) |
145 | - | select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id |
145 | + | |
146 | - | join asset.copy_location acl on acl.id = ac.location |
146 | + | |
147 | - | where acl.name ilike '%juv%' or acl.name ilike '%young%' |
147 | + | |
148 | - | ); |
148 | + | |
149 | FROM rogan.action_circulation circ | |
150 | JOIN actor.org_unit org ON org.id = circ.circ_lib | |
151 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
152 | - | juv_a.circs+juv_not_a.circs as "Total Juvenile Circs - H4", |
152 | + | JOIN asset.copy copy ON copy.id = circ.target_copy |
153 | - | adult_a.circs+coalesce(non.circs,0) as "Adult Print Circs - H5", adult_not_a.circs as "Adult Non-Print Circs - H6", |
153 | + | JOIN asset.call_number call ON call.id = copy.call_number |
154 | join asset.copy_location acl on acl.id = copy.location | |
155 | LEFT OUTER JOIN rogan.circ_ldrs ldrs ON ldrs.circ_id = circ.id | |
156 | WHERE ldrs.circ_ldr != 'a' | |
157 | and ( acl.name ilike '%juv%' or acl.name ilike '%young%' ) | |
158 | GROUP BY 2 | |
159 | ) juv_not_a on juv_not_a.shortname = juv_a.shortname | |
160 | - | WHERE circ.print = true and circ.adult = false |
160 | + | |
161 | SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname | |
162 | FROM rogan.action_circulation circ | |
163 | JOIN actor.org_unit org ON org.id = circ.circ_lib | |
164 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
165 | JOIN asset.copy copy ON copy.id = circ.target_copy | |
166 | JOIN asset.call_number call ON call.id = copy.call_number | |
167 | join asset.copy_location acl on acl.id = copy.location | |
168 | - | WHERE circ.print = true and circ.adult = true |
168 | + | LEFT OUTER JOIN rogan.circ_ldrs ldrs ON ldrs.circ_id = circ.id |
169 | WHERE ldrs.circ_ldr != 'a' | |
170 | and ( acl.name not ilike '%juv%' or acl.name not ilike '%young%' ) | |
171 | GROUP BY 2 | |
172 | ) adult_not_a on adult_not_a.shortname = juv_a.shortname | |
173 | left join ( SELECT coalesce(count(circ.id),0) AS circs, org2.shortname AS shortname | |
174 | FROM action.non_cataloged_circulation circ | |
175 | left JOIN actor.org_unit org ON org.id = circ.circ_lib | |
176 | - | WHERE circ.print = false and circ.adult = false |
176 | + | |
177 | where date(circ.circ_time) >= '2014-07-01' AND date(circ.circ_time) <= '2015-06-30' | |
178 | GROUP BY 2 | |
179 | ) non on non.shortname = juv_a.shortname | |
180 | ; | |
181 | ||
182 | drop table if exists rogan.action_circulation; | |
183 | drop table if exists rogan.circ_ldrs; | |
184 | - | WHERE circ.print = false and circ.adult = true |
184 | + | |
185 | /* | |
186 | ||
187 | -- original form before I created the other tables to query from so it wouldn't take so long to run | |
188 | ||
189 | SELECT juv_a.shortname as "Library", | |
190 | juv_a.circs as "Juvenile Print Circs - H2", juv_not_a.circs as "Juvenile Non-Print Circs - H3", | |
191 | juv_a.circs+juv_not_a.circs as "Total Juvenile Circs - H4", | |
192 | adult_a.circs as "Adult Print Circs - H5", adult_not_a.circs as "Juvenile Non-Print Circs - H6", | |
193 | adult_a.circs+adult_not_a.circs as "Total Adult Circs - H7" | |
194 | FROM ( | |
195 | SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname | |
196 | FROM action.circulation circ | |
197 | JOIN actor.org_unit org ON org.id = circ.circ_lib | |
198 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
199 | JOIN asset.copy copy ON copy.id = circ.target_copy | |
200 | JOIN asset.call_number call ON call.id = copy.call_number | |
201 | join asset.copy_location acl on acl.id = copy.location | |
202 | LEFT OUTER JOIN metabib.real_full_rec meta ON meta.record = call.record | |
203 | WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' | |
204 | AND meta.tag = 'LDR' | |
205 | AND SUBSTRING(meta.VALUE FROM 7 FOR 1) = 'a' | |
206 | and ( acl.name ilike '%juv%' or acl.name ilike '%young%' ) | |
207 | GROUP BY 2 | |
208 | ) juv_a | |
209 | join ( | |
210 | SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname | |
211 | FROM action.circulation circ | |
212 | JOIN actor.org_unit org ON org.id = circ.circ_lib | |
213 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
214 | JOIN asset.copy copy ON copy.id = circ.target_copy | |
215 | JOIN asset.call_number call ON call.id = copy.call_number | |
216 | join asset.copy_location acl on acl.id = copy.location | |
217 | LEFT OUTER JOIN metabib.real_full_rec meta ON meta.record = call.record | |
218 | WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' | |
219 | AND meta.tag = 'LDR' | |
220 | AND SUBSTRING(meta.VALUE FROM 7 FOR 1) = 'a' | |
221 | and ( acl.name not ilike '%juv%' or acl.name not ilike '%young%' ) | |
222 | GROUP BY 2 | |
223 | ) adult_a on adult_a.shortname = juv_a.shortname | |
224 | join ( | |
225 | SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname | |
226 | FROM action.circulation circ | |
227 | - | WHERE copyparent.id != circparent.id AND date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' |
227 | + | |
228 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
229 | JOIN asset.copy copy ON copy.id = circ.target_copy | |
230 | JOIN asset.call_number call ON call.id = copy.call_number | |
231 | join asset.copy_location acl on acl.id = copy.location | |
232 | LEFT OUTER JOIN metabib.real_full_rec meta ON meta.record = call.record | |
233 | WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' | |
234 | AND meta.tag = 'LDR' | |
235 | AND SUBSTRING(meta.VALUE FROM 7 FOR 1) != 'a' | |
236 | and ( acl.name ilike '%juv%' or acl.name ilike '%young%' ) | |
237 | GROUP BY 2 | |
238 | - | WHERE copyparent.id != circparent.id AND date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' |
238 | + | |
239 | join ( | |
240 | SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname | |
241 | FROM action.circulation circ | |
242 | JOIN actor.org_unit org ON org.id = circ.circ_lib | |
243 | JOIN actor.org_unit org2 ON org2.id = org.parent_ou | |
244 | JOIN asset.copy copy ON copy.id = circ.target_copy | |
245 | JOIN asset.call_number call ON call.id = copy.call_number | |
246 | join asset.copy_location acl on acl.id = copy.location | |
247 | LEFT OUTER JOIN metabib.real_full_rec meta ON meta.record = call.record | |
248 | WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' | |
249 | AND meta.tag = 'LDR' | |
250 | AND SUBSTRING(meta.VALUE FROM 7 FOR 1) != 'a' | |
251 | and ( acl.name not ilike '%juv%' or acl.name not ilike '%young%' ) | |
252 | GROUP BY 2 | |
253 | ) adult_not_a on adult_not_a.shortname = juv_a.shortname | |
254 | ; | |
255 | */ | |
256 | ||
257 | ||
258 | /* | |
259 | ||
260 | Interlibrary Loans | |
261 | H14 Provided to another library__________________________ | |
262 | H15 Received from another library__________________________ | |
263 | ||
264 | */ | |
265 | ||
266 | /* | |
267 | -- borrowers at other libraries, these are like reciprocal borrowers | |
268 | select parent.shortname as "Borrowing Library", count(circ.id) as "circs" from action.circulation circ | |
269 | join actor.usr au on au.id = circ.usr | |
270 | join actor.org_unit aou on aou.id = au.home_ou | |
271 | join actor.org_unit parent on parent.id = aou.parent_ou | |
272 | join actor.org_unit aou2 on aou2.id = circ.circ_lib | |
273 | join actor.org_unit parent2 on parent2.id = aou2.parent_ou | |
274 | WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' and parent.id != parent2.id | |
275 | group by 1 order by 1 | |
276 | ; | |
277 | */ | |
278 | ||
279 | select loaners.shortname, loaners.loans as "Provided to another library - H14", borrowers.borrowers as "Received from another library - H15" | |
280 | from ( SELECT copyparent.shortname, COUNT(circ.id) as "loans" | |
281 | FROM ACTION.circulation circ | |
282 | JOIN asset.COPY ac ON ac.id = circ.target_copy | |
283 | JOIN actor.org_unit copychild ON copychild.id = ac.circ_lib | |
284 | JOIN actor.org_unit copyparent ON copyparent.id = copychild.parent_ou | |
285 | JOIN actor.org_unit circchild ON circchild.id = circ.circ_lib | |
286 | JOIN actor.org_unit circparent ON circparent.id = circchild.parent_ou | |
287 | WHERE copyparent.id != circparent.id AND date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-01' | |
288 | GROUP BY 1 | |
289 | ) loaners | |
290 | join ( | |
291 | SELECT circparent.shortname, COUNT(circ.id) as "borrowers" | |
292 | FROM ACTION.circulation circ | |
293 | JOIN asset.COPY ac ON ac.id = circ.target_copy | |
294 | JOIN actor.org_unit copychild ON copychild.id = ac.circ_lib | |
295 | JOIN actor.org_unit copyparent ON copyparent.id = copychild.parent_ou | |
296 | JOIN actor.org_unit circchild ON circchild.id = circ.circ_lib | |
297 | JOIN actor.org_unit circparent ON circparent.id = circchild.parent_ou | |
298 | WHERE copyparent.id != circparent.id AND date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-01' | |
299 | GROUP BY 1 | |
300 | ) borrowers on borrowers.shortname = loaners.shortname | |
301 | order by 1 | |
302 | ; |