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

Опубликовано: 17 Май 2024
на канале: 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).


Смотрите видео Product Sales Analysis III and User Activity for the Past 30 Days I SQL MySQL Leetcode solution онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал CodeWis Technologies by Nuhman Paramban 17 Май 2024. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 4 раз и оно понравилось 0 посетителям.