spool p3a.out
set echo on
set head off
set serveroutput on size 6000
select spj.s#  from spj,p
  where p.color='Red'and spj.p#=p.p# group by spj.s# having avg(qty)>=
        (select avg(qty) from spj,p where p.color='Red' and spj.p#=p.p#)
intersect
select spj.s# from spj,p,j where p.color<>'Red' and j.city='London'
       and spj.p#=p.p# and spj.j#=j.j#;
/
spool off
