0
我有一個表格,當插入這些數據時,該表格包含(除了所有其他數據)信息。現在我想知道插入的頻率(插入每小時(或每15分鐘)的數量)。以下是代碼,我想要實現的。請注意,我也想顯示沒有發生插入的時間間隔(在我的例子中從10:00到11:00)。插入的頻率
if object_id('tempdb..#temp') is not null drop table #temp
create table #temp (Id int identity(1,1), Date datetime)
insert into #temp (Date)
select '2009-10-05 08:01:00' union all
select '2009-10-05 08:22:00' union all
select '2009-10-05 08:23:00' union all
select '2009-10-05 08:24:00' union all
select '2009-10-05 09:30:00' union all
select '2009-10-05 11:01:00' union all
select '2009-10-05 11:05:00' union all
select '2009-10-05 11:52:00' union all
select '2009-10-05 12:01:00' union all
select '2009-10-05 12:05:00' union all
select '2009-10-05 12:07:00' union all
select '2009-10-05 12:09:00' union all
select '2009-10-05 12:20:00' union all
select '2009-10-05 12:30:00' union all
select '2009-10-05 12:40:00' union all
select '2009-10-05 12:50:00' union all
select '2009-10-05 12:55:00' union all
select '2009-10-05 13:30:00' union all
select '2009-10-05 13:35:00' union all
select '2009-10-05 13:40:00' union all
select '2009-10-05 14:01:00'
-- I want to get this data
select '08:00 - 09:00', 4 union all
select '09:00 - 10:00', 1 union all
select '10:00 - 11:00', 0 union all
select '11:00 - 12:00', 3 union all
select '12:00 - 13:00', 9 union all
select '13:00 - 14:00', 3 union all
select '14:00 - 15:00', 1