表AID Date Fee 001 2005-11-01 100
002 2005-11-18 200
003 2005-11-28 200
004 2005-12-10 200
005 2005-12-20 100
006 2006-01-05 300
……表BMonth AllFee2005.11 500
2005.12 300
2006.01 300
……根据表A的数据,得到表B的数据,Sql语句如何写?请指点一下……学习,关注……
002 2005-11-18 200
003 2005-11-28 200
004 2005-12-10 200
005 2005-12-20 100
006 2006-01-05 300
……表BMonth AllFee2005.11 500
2005.12 300
2006.01 300
……根据表A的数据,得到表B的数据,Sql语句如何写?请指点一下……学习,关注……
declare @t table (ID varchar(100) ,[Date] datetime,Fee int)
insert into @t
select '001','2005-11-01',100 union all
select '002','2005-11-18',200 union all
select '003','2005-11-28',200 union all
select '004','2005-12-10',200 union all
select '005','2005-12-20',100 union all
select '006','2006-01-05',300
select * from @tselect convert(varchar(7),[date],102) as [Month] ,sum(fee) as AllFee
from @t
group by convert(varchar(7),[date],102)
group by substring(replace(builddate,'-','.'),1,7)