34,837
社区成员




select a.BlockID as '卡号',
sum(a.SavingTotal)as '期初累计充值',
sum(a.ProductMoney+a.ServerMoney) as '本次充值',
sum (a.SavingTotal+a.ProductMoney+a.ServerMoney) as '充值合计',
sum(case when datediff(day,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end )as '本日消费',
sum(case when datediff(month,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end)as '本月累计消费',
sum(a.AlreadlyConsume)as '已消费金额',
sum(a.[Money]) as '卡内余额'
from tb_ConsumeCar as a
,tb_ClientConsume as b
where a.BlockID=b.BlockID
and ( b.SortType =0 or b.SortType =1 or b.SortType =2)
group by a.BlockID
sum(case when datediff(day,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end )as '本日消费',
select*from
(select a.BlockID as '卡号',
sum(a.SavingTotal)as '期初累计充值',
sum(a.ProductMoney+a.ServerMoney) as '本次充值',
sum (a.SavingTotal+a.ProductMoney+a.ServerMoney) as '充值合计',
sum(case when datediff(day,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end )as '本日消费',
sum(case when datediff(month,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end)as '本月累计消费',
sum(a.AlreadlyConsume)as '已消费金额',
sum(a.[Money]) as '卡内余额'
from tb_ConsumeCar as a
,tb_ClientConsume as b
where a.BlockID=b.BlockID
and ( b.SortType =0 or b.SortType =1 or b.SortType =2)
group by a.BlockID
) t
where 本日消费>0
select a.BlockID as '卡号',
sum(a.SavingTotal)as '期初累计充值',
sum(a.ProductMoney+a.ServerMoney) as '本次充值',
sum (a.SavingTotal+a.ProductMoney+a.ServerMoney) as '充值合计',
sum(case when datediff(day,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end )as '本日消费',
sum(case when datediff(month,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end)as '本月累计消费',
sum(a.AlreadlyConsume)as '已消费金额',
sum(a.[Money]) as '卡内余额'
from tb_ConsumeCar as a
,tb_ClientConsume as b
where a.BlockID=b.BlockID
and ( b.SortType =0 or b.SortType =1 or b.SortType =2)
group by a.BlockID
having (sum(case when datediff(day,b.ConsumeDate,getdate())=0 then (b.ProductMoney+b.ServiceItemMoney+b.ServiceCardMoney) else 0 end )>0)