I want to extract hourly reports of a database for each process, but it has entries every second.
Since this is too much data to work with, I would like to get only the latest update of each hour. I am not an expert in SQL and tried already some "simple" solutions which did not work for me.
I hope you can help me out here.
SELECT
report_id, start_date_local, process,
productivity, dw_last_updated
FROM table_name
WHERE start_date_local > DATEADD(year,-1,GETDATE())
ORDER BY dw_last_updated, ppr_report_id desc
report_id | start_date_local | process | productivity | dw_last_updated |
---|---|---|---|---|
0001 | 2021-01-14 00:00:00.0 | x | 0.0551 | 2021-02-16 06:16:19.0 |
0002 | 2021-01-14 00:00:00.0 | y | 0.0333 | 2021-02-16 06:16:19.0 |
0003 | 2021-01-14 00:00:00.0 | z | 0.0164 | 2021-02-16 06:16:19.0 |
0004 | 2021-01-14 00:00:00.0 | x | 0.0850 | 2021-02-16 06:23:21.0 |
0005 | 2021-01-14 00:00:00.0 | y | 0.0238 | 2021-02-16 06:17:27.0 |
0006 | 2021-01-14 00:00:00.0 | z | 0.0542 | 2021-02-16 06:44:10.0 |
So in this example I would like to get only report_id = 0004, 0005, 0006