Product Sales Analysis III and User Activity for the Past 30 Days I SQL MySQL Leetcode solution

Published: 17 May 2024
on channel: CodeWis Technologies by Nuhman Paramban
4
0

Challenge: Daily Active Users (Past 30 Days)

Difficulty: Easy

Data:

A table named Activity stores information about user activities on a social media platform:

user_id (int): Unique identifier for the user.
session_id (int): Unique identifier for a user session.
activity_date (date): Date the activity occurred.
activity_type (enum): Type of activity performed ("open_session", "end_session", "scroll_down", "send_message").
Objective:

Calculate the number of daily active users for the past 30 days ending on a specific date (inclusive). A user is considered active on a day if they have at least one recorded activity for that day.

Output:

A table with two columns:

day (date): Date for which the active user count is calculated.
active_users (int): Number of users who were active on that day.
Explanation:

We need to identify distinct user_id values for each unique activity_date within the specified date range (past 30 days ending on the provided date). We only care about dates with at least one active user.

Challenge: First Year Sales Analysis

Difficulty: Medium

Data:

Two tables store information about product sales:

SQL MySQL leetcode problem solution
Sales (Primary Key: sale_id, year):
sale_id (int): Unique identifier for a sale.
product_id (int): Foreign key referencing the Product table.
year (int): Year in which the sale occurred.
quantity (int): Number of units sold in this sale.
price (int): Price per unit of the product sold.
Product (Primary Key: product_id):
product_id (int): Unique identifier for a product.
product_name (varchar): Name of the product.
Objective:

Find the product ID, year, quantity, and price for the first year each product was sold.

Output:

A table with four columns:

product_id (int): Unique identifier for the product (same as input table).
first_year (int): Year the product was first sold.
quantity (int): Quantity sold in the first year.
price (int): Price per unit in the first year.
Explanation:

We need to identify the minimum year for each unique product_id in the Sales table. This will represent the first year a product was sold. We can then join with the Product table to retrieve product names (optional).


Watch video Product Sales Analysis III and User Activity for the Past 30 Days I SQL MySQL Leetcode solution online, duration hours minute second in high quality that is uploaded to the channel CodeWis Technologies by Nuhman Paramban 17 May 2024. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 4 times and liked it 0 visitors.