sql 月统计报表 按日显示

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:51:23
总共6个表Card,CardFillDate ,CardFill ,CardReplace,CardRecycle,Mainsavetable
每个表中有2个字段,分别代表时间与收费金额:
Card 表中有addtime,cardmoney字段 (发行时间,发行收费)
CardFillDate 表中有filldate,fillmoney字段 (延期时间,延期收费)
CardFill 表中有filldate,fillmoney字段 (充值时间,充值收费)
CardReplace 表中有replacedate,replacemoney字段 (更换时间,更换收费)
CardRecycle 表中有recycledate,returnmoney字段 (回收时间,回收退费)
Mainsavetable 表中有outdate,chargemoney字段 (出场时间,出场收费)
我想要的查询结果:
日期 发行收费 延期收费 充值收费 更换收费 回收退费 出场收费 小计
2009-03-01 100 50 200 150 500 500 1500
2009-03-02 100 50 200 150 500 600 1600
2009-03-03 100 50 200 150 500 700 1700
2009-03-04 100 50 200 150 500 800 1800
2009-03-05 100 50 200 150 500 900 1900
2009-03-06 100 50 200 150 500 900 1900
...

我写的查询发行收费的语句,不过很不对,请指正!
select convert(nvarchar(10),addtime,120),sum(cardmoney) from car

select a.yd,cardmoney,c.fillmoney,d.fillmoney as fillmoney1,replacemoney,returnmoney,chargemoney from (
select '1' as yd union select '2' union select '3' union
select '5' union select '6' union select '7' union
select '8' union select '9' union select '10' union
select '11' union select '12') a
left join
(select month(addtime)as yd,sum(cardmoney)as cardmoney from Card where year(addtime) = '2009' group by month(addtime)) b
on a.yd=b.yd
left join
(select month(filldate)as yd,sum(fillmoney)as fillmoney from CardFillDate where year(filldate) = '2009' group by month(filldate)) c
on a.yd=c.yd
left join
(select month(filldate)as yd,sum(fillmoney)as fillmoney from CardFill where year(filldate) = '2009' group by month(filldate)) d
on a.yd=d.yd
left join
(select month(replacedate)as yd,sum(re