Write a query that accepts two date and time inputs and returns total minutes by active user, producing a result set like the sample provided with the given assumptions.
Treat the interval as half-open, including the start and excluding the end. Open sessions remain active through the requested end time. Rows with a NULL started_at are ignored, and users with no qualifying activity are excluded.
user_id, user_name, and total_minutes.total_minutes descending, then user_id ascending.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | Display name of the user |
| Column | Type | Description |
|---|---|---|
| session_idPK | INT | Unique session identifier |
| user_id | INT | User associated with the session |
| started_at | TIMESTAMP | Session start timestamp |
| ended_at | TIMESTAMP | Session end timestamp; NULL means the session is open |
| session_label | VARCHAR(50) | Source label for the session |