当前位置:网站首页>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数据抽取时发现的)
边栏推荐
- MATLAB提取不規則txt文件中的數值數據(簡單且實用)
- Using onvif protocol to operate the device
- R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- 【学习笔记】dp 状态与转移
- The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
- Driver development based on I2C protocol
- 高精度室内定位技术,在智慧工厂安全管理的应用
- DS90UB949
- Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
- [VTK] vtkPolydataToImageStencil 源码解读
猜你喜欢

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~

Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power

机器学习 3.2 决策树模型 学习笔记(待补)

Numpy np.max和np.maximum实现relu函数

How to clean up v$rman_ backup_ job_ Details view reports error ora-02030

鸿蒙第三次培训(项目实训)

Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution

多维度监控:智能监控的数据基础

Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation

ASP.NET-酒店管理系統
随机推荐
C语言日志库zlog基本使用
鸿蒙第四次培训
Numpy np.max和np.maximum实现relu函数
How to become a senior digital IC Design Engineer (1-4) Verilog coding syntax: expression
How to: configure ClickOnce trust prompt behavior
P3250 [HNOI2016] 网络 + [NECPC2022] F.Tree Path 树剖+线段树维护堆
Application of high-precision indoor positioning technology in safety management of smart factory
程序员的创业陷阱:接私活
MATLAB提取不规则txt文件中的数值数据(简单且实用)
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
FL Studio 20 unlimited trial fruit arranger Download
One hot code
一些常用术语
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
[vtk] source code interpretation of vtkpolydatatoimagestencil
LeetCode 46:全排列
R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中
R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
[OBS] configFile in ini format of OBS
Excel quick cross table copy and paste