先把两张表连接,amount为null 的正是我们需要的,再按customer_id聚合
select Visits.visit_id,customer_id ,Transactions.visit_id ,transaction_id ,amount
from Visits left join Transactions on Visits.visit_id=Transactions.visit_id
正确代码:
select customer_id , count(customer_id ) count_no_trans
from Visits left join Transactions
on Visits.visit_id = Transactions.visit_id
where amount is null
group by customer_id