  select aid, pid, sum(qty) from orders group by aid, pid;

  select a.aid from agents a where not exists
   (select o.* from orders o, customers c, products p
     where o.aid=a.aid and o.cid=c.cid and o.pid=p.pid
      and c.city='Duluth' and p.city = 'Dallas');

   select distinct cid from orders o
     where aid in ('a03', 'a05') and not exists
     (select * from orders x where 
       o.cid = x.cid and x.aid not in ('a03', 'a05'));


  select aid from agents
    where percent = (select max(percent) from agents);

   update agents set percent = 11 where aname = 'Gray';
   select * from agents;
   update agents set percent = 6 where aname = 'Gray';
   select * from agents;

  select cid, sum(dollars) from orders where aid = 'a04'
    and cid not in (select cid from orders
     where aid != 'a04') group by cid;

  select o.pid from orders o, customers c, agents a
    where o.cid = c.cid and o.aid = a.aid and c.city = a.city;


select discnt from customers where city = 'Duluth';
select percent from agents where city like 'N%';
select city from customers where discnt >=all
  (select discnt from customers where city = 'Duluth' );
select city from agents where percent >any
  (select percent from agents where city like 'N%' );

select city from customers where discnt >=all
  (select discnt from customers where city = 'Duluth' )
  union
  select city from agents where percent >any
    ( select percent from agents where city like 'N%' );

  select * from customers where cname >= 'A' and cname < 'B';

  select a.aname, a.aid, sum(x.dollars) from agents a, orders x
    where a.aid = x.aid group by a.aid, a.aname
  union
  select aname, aid, 0 from agents
    where aid not in (select aid from orders)
  union
  select 'null', aid, sum(x.dollars) from orders x
    where aid not in (select aid from agents) group by aid;


