程序代码:
create table tempTable
(
id int not null primary key identity(1,1),
consumNum char(10) not null,
consumType char(20) not null,
consumMoney decimal not null,
consumTime datetime not null
)
insert into tempTable(consumNum,consumType,consumMoney,consumTime)
values('001','儿童摄影',23,'2010/1/1')
insert into tempTable(consumNum,consumType,consumMoney,consumTime)
values('002','儿童摄影',23,'2010/1/2')
insert into tempTable(consumNum,consumType,consumMoney,consumTime)
values('003','婚纱摄影',500,'2010/1/3')
insert into tempTable(consumNum,consumType,consumMoney,consumTime)
values('004','儿童摄影',23,'2010/1/4')
insert into tempTable(consumNum,consumType,consumMoney,consumTime)
values('005','儿童摄影',23,'2010/2/4')
select consumType,sum(consumMoney) 总和,datepart(mm,consumTime) 月份 from tempTable
group by consumType,datepart(mm,consumTime)
select consumType,sum(consumMoney)总和 from tempTable where consumTime between '2010-01-01' and '2010-01-31 ' group by consumType