开发者

SQL simple selection of rows according to their time

开发者 https://www.devze.com 2022-12-15 20:09 出处:网络
I have a table withmeasures and the time this measures have been taken in the following form: MM/DD/YYYY HH:MI:SS AM. I have measures over many days starting at the same time every day.The datas are m

I have a table with measures and the time this measures have been taken in the following form: MM/DD/YYYY HH:MI:SS AM. I have measures over many days starting at the same time every day.The datas are minute by minute so basically the seconds are always = 0. I want to select only the measures for the first 5 minutes of each day. I开发者_JAVA百科 would have used the where statement but the condition would only be on the minutes and note the date is there a way to do this? Thanks


You could try something like this:

SELECT * FROM SomeTable
WHERE
DATEPART(hh, timestamp_col) = 0 AND -- filter for first hour of the day
DATEPART(mm, timestamp_col) <= 5 -- filter for the first five minutes

Careful! 0 means midnight. If your "first hour" of the day is actually 8 or 9 AM then you should replace the 0 with an 8 or 9.

0

精彩评论

暂无评论...
验证码 换一张
取 消