I need some kind of assistance to fix a problem, below is a table with scan data, i want my sql query to only display records with latest report_created
records for a given project. A project can have multiple scan_id
Example in the below table 8888_super_start should only be displayed once with the latest report_created time and it should only show the latest number of files_scanned.
+--------------------+------------------+---------------+---------------------+---------------------+
| scan_id | project_name | files_scanned | scan_submitted | report_created |
+--------------------+------------------+---------------+---------------------+---------------------+
| ba2468dd-2e38-478a | 8888_super_start | 123 | 2018-01-23 12:58:43 | 2018-01-23 13:48:46 |
| 5d3cb423-4cbb-4196 | 9111_kick_start | 1040 | 2018-01-23 14:57:15 | 2018-01-23 15:58:33 |
| 75ff4cfd-172a-4f2d | 8888_super_start | 180 | 2018-05-25 14:37:33 | 2018-05-25 20:17:19 |
+--------------------+------------------+---------------+---------------------+---------------------+
I tried the approach mentioned in the post but it is not providing proper results. Please provide some suggestions.
Attempt
select sd.scan_id,sd.project_name,sd.files_scanned from blackbox.tb_cx_scan_details sd
left outer join blackbox.tb_cx_scan_details t2
on sd.scan_id = t2.scan_id
and (sd.report_created < t2.report_created
or (sd.report_created = t2.report_created ))
where t2.scan_id is NULL