MySQL的經(jīng)典用法(二)----按月統(tǒng)計數(shù)據(jù)文章分類:數(shù)據(jù)庫 表finance有倆個字段如下
date date money double(15,2) 下面需要對表finance的2010年財務數(shù)據(jù),按月進行統(tǒng)計
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 下面是按周統(tǒng)計 查看MySQL的manual %X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V %x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v 其中 1如果周一為一周的第一天,則(小寫) DATE_FORMAT(date,'%x %v') 2如果周日為一周的第一天,則(大寫) DATE_FORMAT(date,'%X %V')
|
|
|
來自: kekokeko > 《數(shù)據(jù)庫》