1158. Market Analysis I LeetCode Solution

In this guide, you will get 1158. Market Analysis I LeetCode Solution with the best time and space complexity. The solution to Market Analysis I problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Market Analysis I solution in C++
  4. Market Analysis I solution in Java
  5. Market Analysis I solution in Python
  6. Additional Resources
1158. Market Analysis I LeetCode Solution image

Problem Statement of Market Analysis I

Table: Users

+—————-+———+
| Column Name | Type |
+—————-+———+
| user_id | int |
| join_date | date |
| favorite_brand | varchar |
+—————-+———+
user_id is the primary key (column with unique values) 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 (column with unique values) of this table.
item_id is a foreign key (reference column) to the Items table.
buyer_id and seller_id are foreign keys to the Users table.

Table: Items

+—————+———+
| Column Name | Type |
+—————+———+
| item_id | int |
| item_brand | varchar |
+—————+———+
item_id is the primary key (column with unique values) of this table.

Write a solution to find for each user, the join date and the number of orders they made as a buyer in 2019.
Return the result table in any order.
The result format is in the following example.

See also  1124. Longest Well-Performing Interval LeetCode Solution

Example not found

Constraints not found

Complexity Analysis

  • Time Complexity: Google AdSense
  • Space Complexity: Google Analytics

1158. Market Analysis I LeetCode Solution in C++

SELECT
  Users.user_id AS buyer_id,
  Users.join_date,
  COUNT(Orders.order_id) AS orders_in_2019
FROM Users
LEFT JOIN Orders
  ON (Users.user_id = Orders.buyer_id AND YEAR(order_date) = '2019')
GROUP BY 1;
/* code provided by PROGIEZ */

1158. Market Analysis I LeetCode Solution in Java

N/A
// code provided by PROGIEZ

1158. Market Analysis I LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.