zoukankan      html  css  js  c++  java
  • 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
    
    
    
    
  • 相关阅读:
    PHP的函数应用
    MyEclipse 使用Junit
    JAVASE知识点总结
    常见排序算法
    数据结构的java实现
    JDK1.5新特性总结
    Oracle练习题
    Oracle面试题2
    Oracle面试题1
    分别使用Statement和PreparedStatement对数据库进行操作
  • 原文地址:https://www.cnblogs.com/plusUltra/p/10967072.html
Copyright © 2011-2022 走看看