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

Leetcode Problem 1159. Market Analysis II

1159. Market Analysis II

Leetcode Solutions

Analyzing User Orders in with SQL and Pandas

  1. Filter the Orders table to include only orders from the year 2019.
  2. Join the filtered Orders table with the Users table on buyer_id to user_id.
  3. Use a window function (RANK() or ROW_NUMBER()) to assign a rank to each order for each user based on the order_date.
  4. Count the number of orders for each user where the rank is 1, indicating the first order made by the user in 2019.
  5. Select the user_id, join_date, and the count of orders as the final output.
erDiagram
    Users {
        int user_id
        date join_date
        varchar favorite_brand
    }
    Orders {
        int order_id
        date order_date
        int item_id
        int buyer_id
        int seller_id
    }
    Items {
        int item_id
        varchar item_brand
    }
    Users ||--o{ Orders : buyer_id
    Users ||--o{ Orders : seller_id
    Items ||--o{ Orders : item_id

Counting User Orders in Using Group By and Join Operations

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...