Hello evrybody, I have this server
select @@version
Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
And this data table:
select top 20 fecha, hora, valor from datos where id_estacion=1 and tipo_sensor=3 order by fecha desc, hora desc
2018-03-22 00:00:00.000 | 1900-01-01 17:30:00.000 | 1158,7224 |
---|---|---|
2018-03-22 00:00:00.000 | 1900-01-01 17:15:00.000 | 1158,7198 |
2018-03-22 00:00:00.000 | 1900-01-01 17:00:00.000 | 1158,7173 |
2018-03-22 00:00:00.000 | 1900-01-01 16:45:00.000 | 1158,7147 |
2018-03-22 00:00:00.000 | 1900-01-01 16:30:00.000 | 1158,7147 |
2018-03-22 00:00:00.000 | 1900-01-01 16:15:00.000 | 1158,7122 |
2018-03-22 00:00:00.000 | 1900-01-01 16:00:00.000 | 1158,7096 |
2018-03-22 00:00:00.000 | 1900-01-01 15:45:00.000 | 1158,7096 |
2018-03-22 00:00:00.000 | 1900-01-01 15:30:00.000 | 1158,7071 |
2018-03-22 00:00:00.000 | 1900-01-01 15:00:00.000 | 1158,702 |
2018-03-22 00:00:00.000 | 1900-01-01 14:45:00.000 | 1158,6994 |
2018-03-22 00:00:00.000 | 1900-01-01 14:30:00.000 | 1158,6969 |
2018-03-22 00:00:00.000 | 1900-01-01 14:00:00.000 | 1158,6943 |
2018-03-22 00:00:00.000 | 1900-01-01 13:45:00.000 | 1158,6918 |
2018-03-22 00:00:00.000 | 1900-01-01 13:30:00.000 | 1158,6892 |
2018-03-22 00:00:00.000 | 1900-01-01 13:15:00.000 | 1158,6867 |
2018-03-22 00:00:00.000 | 1900-01-01 12:30:00.000 | 1158,6816 |
2018-03-22 00:00:00.000 | 1900-01-01 12:15:00.000 | 1158,679 |
2018-03-22 00:00:00.000 | 1900-01-01 12:00:00.000 | 1158,679 |
2018-03-22 00:00:00.000 | 1900-01-01 11:45:00.000 | 1158,6739 |
I need the last record of each hour of each day, for example, the result must be..
|2018-03-22 00:00:00.000|1900-01-01 17:30:00.000|1158,7224|
|2018-03-22 00:00:00.000|1900-01-01 16:45:00.000|1158,7147|
|2018-03-22 00:00:00.000|1900-01-01 15:45:00.000|1158,7096|
|2018-03-22 00:00:00.000|1900-01-01 14:45:00.000|1158,6994|
|2018-03-22 00:00:00.000|1900-01-01 13:45:00.000|1158,6918|
|2018-03-22 00:00:00.000|1900-01-01 12:30:00.000|1158,6816|
|2018-03-22 00:00:00.000|1900-01-01 11:45:00.000|1158,6739|
How should I do this?
Someone can help me?
Best Regards
Carina