[MySQL]获取当月每一天
mysql 获取 一天 当月
2023-09-27 14:24:46 时间
常用使用场景: 统计某个月(某个时间区间)内每一天的数据量
- select date_add(curdate(), interval(cast(help_topic_id as signed integer) - 1) day) day
- from mysql.help_topic
- where help_topic_id < day(last_day(curdate()))
- order by help_topic_id
延伸用法: 获取一段时间内的每分钟
- set @stime = str_to_date('2018-11-07 08:00', '%Y-%m-%d %H:%i');
- set @etime = str_to_date('2018-11-07 08:10', '%Y-%m-%d %H:%i');
-
- select date_add(@stime, interval (cast(help_topic_id as signed integer) - 0) minute) minute
- from mysql.help_topic
- where help_topic_id <= timestampdiff(minute, @stime, @etime)
- order by help_topic_id
顺便贴一下oracle的写法
- select trunc(sysdate, 'MM') + rownum - 1 day
- from dual
- connect by rownum <= to_number(to_char(last_day(sysdate), 'dd'))
相关文章
- Dapper操作MySQL数据库获取JSON数据中文乱码
- 你想知道的 MySQL 性能调优方式,都在这里
- mysql数据库遍历表,其一字段获取上一条数据
- 关于mysql数据库gbk编码转utf8的问题
- [转]MySQL中timestamp数据类型的特点
- MySQL: window function
- MySQL删除视图(DORP VIEW)
- 二、mysql进程之间关系、配置文件、文件socket、网络socket、mysql密码破解
- mysql如何处理亿级数据,第一个阶段——优化SQL语句
- MYSQL学习
- mysql获取日期(将时间戳转换成短日期格式)
- 设置mysql允许远程连接
- ubuntu 20.10 服务器虚拟机环境搭建(jdk、mysql、nginx、redis)
- 一条SQL语句获取具有父子关系的分类列表(mysql)
- MySQL教程:数据库具体操作
- Mysql中获取行号
- mysql存储过程,获取指定数据库的某个表的字段信息
- Mysql导出逗号分隔的csv文件
- Python获取MySQL的创建表sql,保存到文件中
- mysql中int、bigint、smallint 和 tinyint的区别与长度的含义
- MySQL 分页查询