bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1083. Sales Analysis II

1083. Sales Analysis II

Leetcode Solutions

Using LEFT JOIN and NULL Ids From the Right Table

  1. Join the Sales table with the Product table on product_id to get the product names for each sale.
  2. Use a LEFT JOIN to create a result set that includes all buyers who have bought an S8, along with a list of buyers who have bought an iPhone.
  3. Filter the result set to include only those rows where the buyer_id from the iPhone sales is NULL, indicating that the buyer did not purchase an iPhone.
  4. Select the distinct buyer_id from the filtered result set to get the list of buyers who have bought an S8 but not an iPhone.
erDiagram
    Product ||--o{ Sales : contains
    Product {
        int product_id PK
        varchar product_name
        int unit_price
    }
    Sales {
        int seller_id
        int product_id FK
        int buyer_id
        date sale_date
        int quantity
        int price
    }

Using NOT IN with Subqueries

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...