Given a table of Roku user streaming sessions, write a query to find the session with the longest duration and calculate the average session length per device type.
Assume duration is calculated from started_at and ended_at. Exclude incomplete or invalid sessions, and break a longest-session tie with the lowest session_id.
device_type, average_session_length_minutes, longest_session_id, longest_session_user_id, longest_session_device_type, and longest_session_length_minutes.device_type ascending.| Column | Type | Description |
|---|---|---|
| session_idPK | INT | Unique streaming session identifier |
| user_id | INT | Roku user identifier |
| device_type_id | INT | Referenced Roku device type |
| started_at | TIMESTAMP | Session start timestamp |
| ended_at | TIMESTAMP | Session end timestamp, null for incomplete sessions |
| Column | Type | Description |
|---|---|---|
| device_type_idPK | INT | Unique device type identifier |
| device_type | VARCHAR(80) | Readable Roku device type |
| manufacturer | VARCHAR(80) | Device manufacturer |