I have to categorize the data based on the datetime, on the basis of 15 mins slot, 30 mins slot and 1 hour basis. I wrote the query like this for 1 hour slot,
select
a.datetime, feederid,
vr, vy, vb
from (
select datetime,feederid, vr, vy, vb, tt, DENSE_RANK() OVER (
partition by dateadd(hour, datediff(hour, 0, datetime), 0), feederid
ORDER BY feederid,datetime
) rank1
from pseb.dbo.datasource
where
convert(datetime,datetime) between '2011-06-12' and '2011-06-12 23:59:00'
) a
where rank1 = 1
but i don't know how to partition the data for 15 mins slot values.
My table resultset is like this
DATETIME FeederID VR VY VB
2011-06-12 00:09:50 4731 199.148 0 212.69
2011-06-12 00:05:31 4731 178.531 0 242.838
2011-06-12 00:36:20 4731 174.622 0 239.756
2011-06-12 01:10:03 4731 175.645 0 240.328
2011-06-12 13:10:07 4731 196.387 76.991 241.798
2011-06-12 18:35:46 4731 207.719 54.756 251.855
here 00:00 to 15:00 minutes slot there is 2 records, I need the top 1 order by datetime desc.
Help me to do it.