0bb1f47c2a5bb3df1e3ca36365ebe4cc6c9b8a25
[working/Evergreen.git] /
1 DROP TABLE IF EXISTS audio_bibs;
2 CREATE TEMP TABLE audio_bibs AS
3 select bre.id as bib_id,ac.id as copy_id, ac.circ_lib from biblio.record_entry bre, actor.usr crtr, actor.usr edtr, asset.call_number acn, asset.copy ac
4 where 
5 bre.ID=acn.RECORD AND
6 acn.ID=ac.CALL_NUMBER AND
7
8 not bre.deleted and lower(marc) ~ $$<datafield tag="856" ind1="4" ind2="0">$$ and edtr.id = bre.editor and crtr.id = bre.creator        
9 and
10 (
11         marc ~ $$tag="008">.......................[oqs]$$
12         or
13         marc ~ $$tag="006">......[oqs]$$
14 )
15 and
16 (
17         marc ~ $$<leader>......i$$
18 );
19
20 select * from (select id as system_id from actor.org_unit where parent_ou = 1) as systems
21 join lateral ( select audio_bibs.*,aou.name from audio_bibs join actor.org_unit aou on aou.id = circ_lib where copy_id not in (select target_copy from tattler.ignore_list where org_unit = system_id and report_name = ?) and (select id from actor.org_unit_ancestor_at_depth(circ_lib, 1)) = system_id limit ?) as p on true;