博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL按月/按周统计查询
阅读量:7185 次
发布时间:2019-06-29

本文共 785 字,大约阅读时间需要 2 分钟。

hot3.png

按月进行统计

[sql]select DATE_FORMAT(date,'%Y-%m') as month,sum(money) as moneyfrom financewhere DATE_FORMAT(date,'%Y')=2010 group by monthorder by month[/sql]

按周统计

查看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')

[sql]select DATE_FORMAT(date,'%x年-第%v周') as week,sum(money) as money from finance_base where DATE_FORMAT(date,'%Y')=2010 group by weekselect DATE_FORMAT(date,'%x年-第%v周') as week,sum(money) as money from finance_base where DATE_FORMAT(date,'%Y')=2010 group by week[/sql]

转载于:https://my.oschina.net/liufeng815/blog/353544

你可能感兴趣的文章
Window系统下用Ant实现Java项目的自动构建和部署
查看>>
Selenium IDE测试
查看>>
BZOJ4327:[JSOI2012]玄武密码(SAM)
查看>>
Java过滤器与SpringMVC拦截器之间的关系与区别
查看>>
linux学习 (2015-1)
查看>>
关于Visual Studio无法连接到Visual Studio 的Localhost Web服务器问题
查看>>
二、Java面向对象(7)_封装思想——package语句
查看>>
TPYBoard—MicroPython开发板免费试用!你最想抱走哪款?
查看>>
JAVA面试准备
查看>>
android获取系统信息
查看>>
oracle 跨库访问
查看>>
Stanford parser学习:LexicalizedParser类分析
查看>>
【mysql】在mysql中更新字段的部分值,更新某个字符串字段的部分内容
查看>>
android WebView onJsAler onJsC…
查看>>
Java之谜 —— 来自Neal Gafter的演讲
查看>>
js压缩反压缩
查看>>
jdbc.properties 包含多种数据库驱动链接的版本。
查看>>
mac 安装mysql
查看>>
Event Managers
查看>>
14-python-函数
查看>>