← 返回 bytedance 的题目列表SQL Query Session
类型:online_judge
bytedance
Write an SQL query to retrieve the count of daily new active users from the 'users' table for the past 30 days. The structure of the 'users' table is:
CREATE TABLE users (
user_id INT,
active_date DATE
);
Requirements:
The result should include two columns: date and new_active_users.
The result should be sorted by date in ascending order.
There may be duplicate active_date entries in the database, ensure each user is counted only once per day.
Export the result to a CSV file ensuring the output format adheres to the following:
Example Output:
| date | new_active_users | |------------|------------------| | 2023-10-01 | 100 | | 2023-10-02 | 150 |
Data Scale:
Up to 100,000 rows of data per day.
During testing, provide data for at least 10 days to verify the accuracy of the query.
Example
Input
CREATE TABLE users (user_id INT, active_date DATE); INSERT INTO users VALUES (1, '2023-09-30'), (2, '2023-09-30'), (3, '2023-10-01'), (1, '2023-10-02');