当前位置:网站首页>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数据抽取时发现的)
边栏推荐
- Arctangent entropy: the latest SCI paper in July 2022
- After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
- Oracle withdraw permission & create role
- phpcms 提示信息页面跳转showmessage
- 鸿蒙第三次培训(项目实训)
- How to mix embedded MCU, arm and DSP?
- Double linked list of linear list
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
- Excel quick cross table copy and paste
- 如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
猜你喜欢

导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....

Viewing binary bin files with notepad++ editor

After using the thread pool for so long, do you really know how to reasonably configure the number of threads?

Redis things

Excel表格转到Word中,表格不超边缘纸张范围

AOSP ~ NTP ( 网络时间协议 )

ASP. Net hotel management system

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)

Intel 13th generation core flagship exposure, single core 5.5ghz

Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
随机推荐
Qt+VTK+OCCT读取IGES/STEP模型
[OBS] encapsulate the basic process of OBS acquisition
一些常用术语
How to make others fear you
Understand go language context in one article
1. Hal driven development
Oracle withdraw permission & create role
AIDL
Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
[vtk] source code interpretation of vtkpolydatatoimagestencil
R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
C语言日志库zlog基本使用
用了这么久线程池,你真的知道如何合理配置线程数吗?
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
C language two-dimensional array
Incremental database backup - DB incr DB full
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func mai
Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
R language uses data The table package performs data aggregation statistics, calculates window statistics, calculates the median of sliding groups, and merges the generated statistical data into the o
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3