34,593
社区成员
发帖
与我相关
我的任务
分享
select wid,count(distinct(Wid)) from TableTime
where datediff(mm,ton,@time)=0 or datediff(mm,toff,@time)=0
create table TableTime
(
wid int,
Ton datetime,
Toff datetime
)
go
insert into TableTime
select 1,'2009-10-1','2009-10-2' union all
select 1,'2009-10-1','2009-10-2' union all
select 1,'2009-11-1','2009-11-2'
go
declare @month int
set @month=11
select wid,count(wid)as num from TableTime where datepart(month,Ton)=@month or datepart(month,Toff)=@month group by wid
--修改下
select
wid,count(distinct(Wid))
from
TableTime
where
datediff(mm,ton,@time)=0 or datediff(mm,toff,@time)=0
group by
wid
select
wid,count(distinct(Wid))
from
TableTime
where
datediff(mm,ton,@time)=0 or datediff(mm,toff,@time)=0
select Wid,count(1) from TableTime where datepart(mm,Ton) = 2 or datepart(mm,Toff) = 2 group by Wid