要创建一个可以每个小时报告的查询,首先要创建一个表格。该表格一列记录日期,而没有时间信息;另一列记录钟点。下面的表格有一列记录了不同的处理类型。例如,我们可以按小时找出处理类型的总数。 create table test
(starttime datetime not null
default current_timestamp,
startdate datetime not null
default convert(datetime, convert(char(10),current_timestamp, 110)),
starthour int not null
default datepart(hh,current_timestamp),
trantype int not null
constraint ck_trantype check ( trantype in
(
1, -- insert
2, -- 0update
3, -- 0delete
)
default 1
)
go