当前位置:网站首页>Mysql根据时间搜索常用方法整理
Mysql根据时间搜索常用方法整理
2022-07-03 10:46:00 【追逐梦想永不停】
1.使用date_sub
查询3天内的数据
select * from mytable where update_time > date_sub(curdate(),interval 3 DAY)
此时,update_time
为datetime、date、timestamp
等类型时,可以使用。
2.使用to_days
查询3天内的数据
select * from mytable where 3 > to_days(now())-to_days(update_time)
此时,update_time
为datetime、date、timestamp
等类型时,可以使用。
3.时间转字符的方法,DATE_FORMAT
select DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%S') from mytable
4.字符转时间的方法,STR_TO_DATE
select str_to_date('2022/06/24','%Y/%m/%d');
5.字符转时间再转Timestamp的方法,UNIX_TIMESTAMP(不常用)
select UNIX_TIMESTAMP(str_to_date('2022/06/24','%Y/%m/%d'));
注意,这个方法不常用;如果想把datetime、date类型的数据查询出来、保存到timestamp列,只需要直接保存即可,无需转换;
如果想把字符类型的数据查询出来、保存到timestamp列,只需要转换为时间类型、然后保存即可,无需转换为timestamp;转换后反而会报错。(kettle数据抽取时发现的)
边栏推荐
- 软考中级软件设计师该怎么备考
- Excel表格转到Word中,表格不超边缘纸张范围
- R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
- The excel table is transferred to word, and the table does not exceed the edge paper range
- Tablespace creation management and control file management
- Excel quick cross table copy and paste
- Using onvif protocol to operate the device
- Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
- MATLAB提取不規則txt文件中的數值數據(簡單且實用)
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
猜你喜欢
随机推荐
Qt+VTK+OCCT读取IGES/STEP模型
[VTK] vtkWindowedSincPolyDataFilter 源码注释解读
Program process management tool -go Supervisor
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
AOSP ~ NTP ( 网络时间协议 )
机器学习 3.2 决策树模型 学习笔记(待补)
P3250 [HNOI2016] 网络 + [NECPC2022] F.Tree Path 树剖+线段树维护堆
鸿蒙第四次培训
CSRF
This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
How to become a senior digital IC Design Engineer (1-2) Verilog coding syntax: Verilog 1995, 2001, 2005 standards
如何成为一名高级数字 IC 设计工程师(1-5)Verilog 编码语法篇:操作数
Numpy np.max和np.maximum实现relu函数
Excel表格转到Word中,表格不超边缘纸张范围
Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
Execute kubectl on Tencent cloud container service node
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution