Which investors have some transactions?
select * from investors as t1 join transactions as t2 on t1.investor_id = t2.investor_id
How many of these investors are there?
select count(distinct t1.investor_id) from investors as t1 join transactions as t2 on t1.investor_id = t2.investor_id
How about those who have at least two transactions with type code "SALE"?
select count(*) from (select count(*) from investors as t1 join transactions as t2 on t1.investor_id = t2.investor_id where t2.transaction_type_code = "SALE" group by t2.investor_id having count(*) >= 2)
OK，give me their ids and details.
select t2.investor_id, t1.investor_details from investors as t1 join transactions as t2 on t1.investor_id = t2.investor_id where t2.transaction_type_code = "SALE" group by t2.investor_id having count(*) >= 2