sql - Selecting Record based on last hour of the day -

basically have database retrieves data each minute of day. has occurred on past 3 years in company. looking query pull records each day @ 11:00:00pm. have timestamp column , have tried following not generate results. timestamp format follows 2011-10-13 16:59:00.000.
select * waterusage timestamp '%23:00:00%'
thank you.
update: following formula seems work leaves out few days...not sure why..
with cte (
select *, row_number() over(partition datediff(d, 0, timestmp) order timestmp desc) rn waterusage ) select * cte
rn = 1
update: works if retrieve yearly results within timeframe. select * waterusage timestmp > '2011' , timestmp < '2012'
correct answer put white space @ beginning cause timestamp date + time.
select * waterusage timestmp '% 23:%'` another way:
select * waterusage unix_timestamp(timestmp)%86400 > 82800 you need check performance these 2 options.
Comments
Post a Comment