SQL Interview Questions – Customer Who Visited but Did Not Make Any Transactions

Spread the love

Problem Description –

Write an SQL query to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.

Return the result table sorted in any order.

The query result format is in the following example.

Problem Link – customer who visited

Difficulty Level – Easy

Solution –

SELECT
    customer_id,
    COUNT(*) as count_no_trans
FROM Visits
WHERE visit_id NOT IN (SELECT DISTINCT visit_id FROM transactions)
GROUP BY 1

Rating: 1 out of 5.

Leave a Reply