`

MySQL----按月统计数据

阅读更多
统计2010年 每月的资金
select DATE_FORMAT(date,'%Y-%m') as month,sum(money) as money 
from finance 
where DATE_FORMAT(date,'%Y')=2010 
group by month 
order by month


1如果周一为一周的第一天,则(小写) DATE_FORMAT(date,'%x %v')
2如果周日为一周的第一天,则(大写) DATE_FORMAT(date,'%X %V')

统计每个星期
select DATE_FORMAT(date,'%x年-第%v周') as week,sum(money) as money 
from finance_base 
where DATE_FORMAT(date,'%Y')=2010 
group by week

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics