• mysql查询特定时间段内的数据


    例如查询某张表2019年5月,06点-09点间的数据。
    select date from <表名> where month(列名)='5' AND extract(hour_minute from <列名>) BETWEEN '600' AND '859' (注意mysql between and 是包含两边的)

    MySQL日期时间Extract函数的优点在于可以选取日期时间的各个部分,从年一直到微秒,让我们对MySQL日期时间的处理更为轻松。

    MySQL 日期时间 Extract(选取)函数。

    1. 选取日期时间的各个部分:日期、时间、年、季度、月、日、小时、分钟、秒、微秒
    set @dt = '2008-09-10 07:15:30.123456';  
    select date(@dt); -- 2008-09-10  
    select time(@dt); -- 07:15:30.123456  
    select year(@dt); -- 2008  
    select quarter(@dt); -- 3  
    select month(@dt); -- 9  
    select week(@dt); -- 36  
    select day(@dt); -- 10  
    select hour(@dt); -- 7  
    select minute(@dt); -- 15  
    select second(@dt); -- 30  
    select microsecond(@dt); -- 123456
    
    1. MySQL Extract() 函数,可以上面实现类似的功能
    
    set @dt = '2008-09-10 07:15:30.123456';  
    select extract(year from @dt); -- 2008  
    select extract(quarter from @dt); -- 3  
    select extract(month from @dt); -- 9  
    select extract(week from @dt); -- 36  
    select extract(day from @dt); -- 10  
    select extract(hour from @dt); -- 7  
    select extract(minute from @dt); -- 15  
    select extract(second from @dt); -- 30  
    select extract(microsecond from @dt); -- 123456  
     
    select extract(year_month from @dt); -- 200809  
    select extract(day_hour from @dt); -- 1007  
    select extract(day_minute from @dt); -- 100715  
    select extract(day_second from @dt); -- 10071530  
    select extract(day_microsecond from @dt); -- 10071530123456  
    select extract(hour_minute from @dt); -- 715  
    select extract(hour_second from @dt); -- 71530  
    select extract(hour_microsecond from @dt); -- 71530123456  
    select extract(minute_second from @dt); -- 1530  
    select extract(minute_microsecond from @dt); -- 1530123456  
    select extract(second_microsecond from @dt); -- 30123456
    
    
    
    
  • 相关阅读:
    嵌入式开发杂谈
    C#连接数据库
    C软件机密解密之动态跟踪
    navicat连接mysql8报错
    tomcat 服务版本内存设置
    python2/python3 升级pi版本
    各种源文件和目录
    Day 2 : 变量、JAVA基本类型、运算符和表达式1
    猜字母游戏
    Day 1 : 行业概述、JAVA开发环境
  • 原文地址:https://www.cnblogs.com/plusUltra/p/10967072.html
Copyright © 2020-2023  润新知