Market Analysis II

4pts
Shopify

Problem Statement

Shopify wants to know if sellers are successful in selling their favorite brands.

Write an SQL query to find for each seller, whether the brand of the second item (by date) they sold is their favorite brand.

Rules:

  • If a seller has sold less than two items, report 'no'.
  • Output columns: seller_id, second_item_fav_brand.
  • Results must be sorted by seller_id in ascending order.
Tests your understanding of
Window Functions, Joins and Case Statements

Input Tables

Users
user_id(INTEGER)join_date(DATE)favorite_brand(VARCHAR)
12026-01-01Apple
22026-01-02Samsung
32026-01-03Sony
Orders
order_id(INTEGER)order_date(DATE)item_id(INTEGER)seller_id(INTEGER)
12026-02-01101
22026-02-02111
32026-02-01122
Items
item_id(INTEGER)item_brand(VARCHAR)
10Samsung
11Apple
12Samsung

Expected Output

seller_id(INTEGER)second_item_fav_brand(VARCHAR)
1yes
2no
3no

Tags

MediumWindow FunctionsJoinsCase Statements
25-30 min
46%

Hints