Использовать DISTINCT
:
select count(distinct c.id)
from customers c inner join
transactions t on t.customer_id = c.id
where t.is_swipe = 'Y' and
t.created_date between '2019-01-01' and '2019-12-31' and
t.is_swipe > 0;
Вы можете использовать INNER JOIN
, чтобы проверять только совершенную транзакцию клиента вместо LEFT JOIN
.
Однако вы также можете использовать exists
:
select count(c.id)
from customers c
where exists (select 1
from transactions t
where t.created_date between '2019-01-01' and '2019-12-31' and
t.is_swipe > 0 and
t.customer_id = c.id
);