I want all US customers (cust.id is unique) who have spent > $30 from 1/1/06 to 12/31/06. Invoice subtotals and dates are from invoice table (cust.id is 1 to many to invoice.id). I also want to exclude any cust records with flag=1 or flag=2 in flag table (cust.id is 1 to many to flag.id). How do I write the invoice select and fit it into the rest of this?
select * from cust c
where c.country='us'
and c.id not in
(select f.id from flags f
where (f.flag_id=1)
or (f.flag_id=2))
select * from cust c
where c.country='us'
and c.id not in
(select f.id from flags f
where (f.flag_id=1)
or (f.flag_id=2))