您的位置:首页 > 数据库

实现按月消费统计的SQL语句

2009-06-03 12:16 417 查看
USE EcardSystem
select a.月份,消费金额=sum(a.消费金额),早餐金额=sum(a.早餐金额),中餐金额=sum(a.中餐金额),晚餐金额=sum(a.晚餐金额) from
(
SELECT 月份=month(jndate),
消费金额=(-sum(jnsum)/100),
早餐金额=CASE
when meals='1' then (-sum(jnsum)/100) end,
中餐金额=CASE
when meals='2' then (-sum(jnsum)/100) end,
晚餐金额=CASE
when meals='3' then (-sum(jnsum)/100) end
FROM histrjn where (account='*****'and year(jndate)=2009) group by meals,month(jndate)
)as a
group by a.月份
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql