22,207
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb')is not null drop table tb
go
create table tb(date datetime ,id varchar(20), )
insert tb select
'2009-08-30 08:00:00', 'A' union all select
'2009-08-30 09:00:00', 'B' union all select
'2009-08-31 08:00:00' , 'C' union all select
'2009-08-31 07:00:00' , 'D' union all select
'2009-08-29 06:00:00' , 'E'
select cast(cast(date as varchar(10)) as datetime) as date,count(*)as num
from tb group by cast(cast(date as varchar(10)) as datetime)
date num
----------------------- -----------
2009-08-29 00:00:00.000 1
2009-08-30 00:00:00.000 2
2009-08-31 00:00:00.000 2
(3 行受影响)
WHERE date_col >= '2009-08-30' AND date_col < DATEADD(day,1,'2009-08-30');
select cast(cast('2009-08-30 17:00:01' as varchar(10)) as datetime)
select cast(cast('2009-08-30 17:00:01' as varchar(10) as datetime)