读书人

MySQL-按月统计数据

发布时间: 2012-08-28 12:37:01 作者: rapoo

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

读书人网 >Mysql

热点推荐