You are given two tables: Visits and Transactions.
The Visits table contains information about customers who visited the mall, with each visit having a unique visit_id and associated customer_id.
The Transactions table contains information about transactions made during visits, linking each transaction to a specific visit_id.
Task: Find the IDs of customers who visited the mall but did not make any transactions, along with the count of such visits for each customer.
Return the result table sorted in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
visit_id
PK
|
int | Unique identifier for each visit |
customer_id
|
int | ID of the customer who made the visit |
| Column Name | Type | Description |
|---|---|---|
transaction_id
PK
|
int | Unique identifier for each transaction |
visit_id
|
int | Foreign key linking to the visit when transaction occurred |
amount
|
int | Transaction amount |
Input & Output
| visit_id | customer_id |
|---|---|
| 1 | 23 |
| 2 | 9 |
| 4 | 30 |
| 12 | 23 |
| transaction_id | visit_id | amount |
|---|---|---|
| 2 | 12 | 20 |
| customer_id | count_no_trans |
|---|---|
| 9 | 1 |
| 30 | 1 |
Customer 23 made 2 visits (visit_id 1 and 12), but only visit 12 resulted in a transaction. Since we need customers with only non-transaction visits, customer 23 is excluded. Customers 9 and 30 each made 1 visit without any transactions, so they appear in the result.
| visit_id | customer_id |
|---|---|
| 1 | 54 |
| 2 | 54 |
| 3 | 54 |
| transaction_id | visit_id | amount |
|---|
| customer_id | count_no_trans |
|---|---|
| 54 | 3 |
Customer 54 visited 3 times (visits 1, 2, and 3) but never made any transactions. The result shows customer 54 with 3 non-transaction visits.
| visit_id | customer_id |
|---|---|
| 1 | 23 |
| 2 | 9 |
| transaction_id | visit_id | amount |
|---|---|---|
| 1 | 1 | 100 |
| 2 | 2 | 50 |
| customer_id | count_no_trans |
|---|
Every visit resulted in a transaction, so no customers have non-transaction visits. The result is empty.
Constraints
-
1 ≤ visit_id ≤ 100 -
1 ≤ customer_id ≤ 100 -
1 ≤ transaction_id ≤ 100 -
1 ≤ amount ≤ 1000