Leetcode Problem 1581. Customer Who Visited but Did Not Make Any Transactions

1581. Customer Who Visited but Did Not Make Any Transactions

Leetcode Solutions

Identifying Customers with Visits but No Transactions

Algorithm

  1. Perform a LEFT JOIN between the Visits and Transactions tables on the visit_id column.
  2. Use a WHERE clause to filter for records where transaction_id is NULL from the Transactions table.
  3. Group the results by customer_id.
  4. Use the COUNT function to count the number of visits without transactions for each customer.
  5. Select the customer_id and the count as count_no_trans.
  6. Return the result set.

erDiagram
    Visits {
        int visit_id PK
        int customer_id
    }

    Transactions {
        int transaction_id PK
        int visit_id FK
        int amount
    }

    Visits ||--o{ Transactions : has

Identifying Customers with Visits but No Transactions Using Subquery

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...