1159. Market Analysis II

https://leetcode.com/problems/market-analysis-ii

Description

Table: Users

+----------------+---------+
| Column Name    | Type    |
+----------------+---------+
| user\_id        | int     |
| join\_date      | date    |
| favorite\_brand | varchar |
+----------------+---------+
user\_id is the primary key of this table.
This table has the info of the users of an online shopping website where users can sell and buy items.

Table: Orders

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| order\_id      | int     |
| order\_date    | date    |
| item\_id       | int     |
| buyer\_id      | int     |
| seller\_id     | int     |
+---------------+---------+
order\_id is the primary key of this table.
item\_id is a foreign key to the Items table.
buyer\_id and seller\_id are foreign keys to the Users table.

Table: Items

Write an SQL query to find for each user, whether the brand of the second item (by date) they sold is their favorite brand. If a user sold less than two items, report the answer for that user as no.

It is guaranteed that no seller sold more than one item on a day.

The query result format is in the following example:

ac

Last updated

Was this helpful?