declare @tb1 table(id int,nodetail int,detailed int,date datetime) insert into @tb1 select 1,2,2,'2010-9-10' union all select 2,2,2,'2010-9-11' union all select 3,2,2,'2010-9-12' union all select 4,2,2,'2010-9-13' union all select 5,2,2,'2010-9-14' union all select 6,2,2,'2010-9-15' union all select 7,2,2,'2010-10-10' union all select 8,2,2,'2010-10-11' union all select 9,2,2,'2010-10-12' union all select 10,2,2,'2010-10-13' union all select 11,2,2,'2010-11-14' union all select 12,2,2,'2010-11-15' select [month]=month(date),alldetail=sum(nodetail+detailed),nodetail=sum(nodetail),detailed=sum(detailed) from @tb1 group by month(date) /* 9 24 12 12 10 16 8 8 11 8 4 4 */
select count(id) as allnum, sum(case when Note=1 then 1 else 0 end) waitnum, sum(case when Note=3 then 1 else 0 end) donenum from Administrative 如果我这样写有没有问题,我就想让它自动安装系统时间去划分
insert into @tb1
select 1,2,2,'2010-9-10' union all
select 2,2,2,'2010-9-11' union all
select 3,2,2,'2010-9-12' union all
select 4,2,2,'2010-9-13' union all
select 5,2,2,'2010-9-14' union all
select 6,2,2,'2010-9-15' union all
select 7,2,2,'2010-10-10' union all
select 8,2,2,'2010-10-11' union all
select 9,2,2,'2010-10-12' union all
select 10,2,2,'2010-10-13' union all
select 11,2,2,'2010-11-14' union all
select 12,2,2,'2010-11-15'
select [month]=month(date),alldetail=sum(nodetail+detailed),nodetail=sum(nodetail),detailed=sum(detailed) from @tb1
group by month(date)
/*
9 24 12 12
10 16 8 8
11 8 4 4
*/
select count(id) as allnum,
sum(case when Note=1 then 1 else 0 end) waitnum,
sum(case when Note=3 then 1 else 0 end) donenum
from Administrative
如果我这样写有没有问题,我就想让它自动安装系统时间去划分
去baidu或者GG搜 sql server job
2 count(待处理的统计数)
3 count(*)-count(待处理的统计数)