sql - How break a time range between n numbers of equal intervals? -


timemin: 2015-04-29 10:57:56.623

timemax: 2015-04-29 11:04:35.133

i trying write select query break n equal intervals

this attempt:

declare @min int select @min  = min(datediff(ss,'1970-01-01', biddate)) tbl_bids declare @max int select @max  = max(datediff(ss,'1970-01-01', biddate)) tbl_bids  declare @numparts int  select @numparts =count(*) tbl_bids  select ((datediff(ss,'1970-01-01', biddate) * (@max - @min) / @numparts) + 1) - ((@max - @min) / @numparts),  (datediff(ss,'1970-01-01', biddate) * (@max - @min) / @numparts) + 1 tbl_bids  datediff(ss,'1970-01-01', biddate)<= @numparts 

but returns 0 rows.

example:

min: 2015-04-29 10:50:00

max: 2015-04-29 11:00:00

if numparts = 5 (breaking 5 equal intervals)

output should be:

2015-04-29 10:52:00 2015-04-29 10:54:00 2015-04-29 10:56:00 2015-04-29 10:58:00 2015-04-29 11:00:00 

you can total diff of seconds between dates , use equal parts. this.

declare @dt_min datetime = '2015-04-29 10:50:00'  declare @dt_max datetime = '2015-04-29 11:00:00'  declare @parts int = 5 declare @sec bigint = datediff(second,@dt_min,@dt_max)/@parts  select top (@parts) dateadd(second,@sec*(row_number()over(order (select 1)) - 1) ,@dt_min) sys.tables 

and query, this.

declare @dt_min datetime select @dt_min  = min(biddate) tbl_bids declare @dt_max datetime select @dt_max  = max(biddate) tbl_bids  declare @numparts int  select @numparts =count(*) tbl_bids  declare @sec bigint = datediff(second,@dt_min,@dt_max)/@numparts  select dateadd(second,@sec*(row_number()over(order biddate) - 1) ,@dt_min) tbl_bids 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -