Example
.NAME books2
.OUTPUT books2.out
.LONGREMARK
The BOOKS2 report demonstrates using setup
and cleanup to produce temporary tables.
.ENDREMARK
.SETUP
set lockmode session where readlock=nolock;
create view tempbooks as
select b.id, b.title, a.name, '' as subject,
1 as code
from book b, author a
where b.id = a.id
union
select b.id, b.title, '' as name, s.subject,
2 as code
from book b, subject s
where b.id = s.id;
create table subj_count as
select id, count(subject) as num_sub
from tempbooks
where code = 2
group by id;
create table auth_count as
select id, count(name) as num_auths
from tempbooks
where code = 1
group by id;
.CLEANUP
drop tempbooks;
drop subj_count;
drop auth_count;
.QUERY
select b.id, b.title, b.name, b.subject, b.code,
a.num_auths, s.num_sub
from tempbooks b,subj_count s,auth_count a
where b.id = a.id and b.id = s.id