Write a SQL query to find the most recent record for each test case and environment.
Use the provided test_cases and test_records tables. Treat records with the same test case and environment as one group, and use record_id as the final tie-breaker when timestamps match.
test_case_id, test_case_name, environment, record_id, executed_at, and statustest_case_id, environment with NULL environments first, then newest timestamp and highest record ID| Column | Type | Description |
|---|---|---|
| test_case_idPK | INT | Unique identifier for a test case |
| test_case_name | VARCHAR(150) | Readable test case name |
| team_name | VARCHAR(100) | Team responsible for the test case |
| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique execution record identifier |
| test_case_id | INT | Referenced test case identifier |
| environment | VARCHAR(50) | Execution environment |
| executed_at | TIMESTAMP | Execution timestamp |
| status | VARCHAR(20) | Execution outcome |
| result_detail | TEXT | Optional execution detail |