当前位置:网站首页>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数据抽取时发现的)
边栏推荐
- Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture
- ASP. Net hotel management system
- R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- Arctangent entropy: the latest SCI paper in July 2022
- Incremental database backup - DB incr DB full
- 按键切换:按F1-F12都需要按Fn
- C语言二维数组
- [OBS] configFile in ini format of OBS
- How to make others fear you
- R语言使用原生包(基础导入包、graphics)中的hist函数可视化直方图(histogram plot)
猜你喜欢

Arctangent entropy: the latest SCI paper in July 2022

Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)

Machine learning 3.2 decision tree model learning notes (to be supplemented)

软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。

聊聊Flink框架中的状态管理机制

LeetCode 46:全排列

活动预告 | 直播行业“内卷”,以产品力拉动新的数据增长点

C语言 AES加解密

【学习笔记】dp 状态与转移

The excel table is transferred to word, and the table does not exceed the edge paper range
随机推荐
repo ~ 常用命令
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
[vtk] source code interpretation of vtkpolydatatoimagestencil
One hot code
动态规划(区间dp)
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
Project management essence reading notes (VII)
Intel 13th generation core flagship exposure, single core 5.5ghz
00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
Redis things
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
基于I2C协议的驱动开发
Reading notes: heart like Bodhi, Cao Dewang
JGG专刊征稿:时空组学
Modular programming of single chip microcomputer
基于turtlebot3实现SLAM建图及自主导航仿真
Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
C语言二维数组
The world's most popular font editor FontCreator tool