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
    
    
    
    
  • 相关阅读:
    一组sharepoint中组合各种功能的JavaScript
    两个完全一样的listview,将第一个中的全部数据复制到第二个中去
    一些测试网站性能的在线免费工具
    C#(WIN FORM)两个窗体间LISTVIEW值的修改
    好的书
    a*寻路算法
    Web网站的性能测试工具
    解决网站中加载js代码速度慢的问题
    SqlDataAdapter和SqlCommand
    Asp.net 备份和还原SQL Server及压缩Access数据库
  • 原文地址:https://www.cnblogs.com/plusUltra/p/10967072.html
Copyright © 2011-2022 走看看