create table tb(日期 datetime,路单编号 varchar(10),行驶公里 int)
insert into tb select '2005-01-02','0001',100
union all select '2005-01-03','0002',200
union all select '2005-01-05','0003',300
union all select '2005-02-02','0004',400
union all select '2005-04-02','0005',100select 月份=convert(char(7),日期,120),
路单数量=count(*),
累计公里数=sum(行驶公里)
from tb
group by convert(char(7),日期,120)
drop table tb--这个意思?
insert into tb select '2005-01-02','0001',100
union all select '2005-01-03','0002',200
union all select '2005-01-05','0003',300
union all select '2005-02-02','0004',400
union all select '2005-04-02','0005',100select 月份=convert(char(7),日期,120),
路单数量=count(*),
累计公里数=sum(行驶公里)
from tb
group by convert(char(7),日期,120)
drop table tb--这个意思?
count(路单编号) as 路单统计,
count(行驶公里) as 行驶公里
from a
group by DATEPART(year, 日期) + DATEPART(month, 日期)
count(路单编号) as 路单统计,
sum(行驶公里) as 行驶公里
from a
group by DATEPART(year, 日期) + DATEPART(month, 日期)