zoukankan      html  css  js  c++  java
  • MySQL 查询大于“时间字段”15分钟、1小时、1天的数据

     

    以下代码中times为时间字段,类型为datetime

    1.查询大于times十五分钟的数据

    //大于号后面都是获取times十五分钟后的时间
    select*from table where now() >SUBDATE(times,interval -15 minute);
    select*from table where now() > SUBDATE(times,interval -900 second);
    select*from table where now() > date_add(times,interval 15 minute);
    select*from table where now() >ADDDATE(times,interval 15 minute);

    2.查询大于times一小时的数据

    //大于号后面都是获取times一小时后的时间
    select*from table where now() >SUBDATE(times,interval -1 hour);
    select*from table where now() > SUBDATE(times,interval -60*60 second);
    select*from table where now() > date_add(times,interval -1 hour);
    select*from table where now() >ADDDATE(times,interval 15 hour);

    3.查询大于times一天的数据

    //大于号后面都是获取times一天后的时间
    select*from table where now() >SUBDATE(times,interval -1 day);
    select*from table where now() > SUBDATE(times,interval -60*60*60 second);
    select*from table where now() > date_add(times,interval -1 day);
    select*from table where now() >ADDDATE(times,interval 15 day);

    相应的如果想查询前一天的数据,加一个“-”号即可

  • 相关阅读:
    构建之法阅读笔记02
    第六周总结
    第四周总结
    课堂练习——数据爬取
    【Spring实战4】02---Spring容器
    【Spring实战4】01---初接触
    性能测试总结(三)--工具选型篇
    性能测试总结(二)---测试流程篇
    性能测试总结(一)---基础理论篇
    接口测试总结【转】
  • 原文地址:https://www.cnblogs.com/liangzia/p/11910379.html
Copyright © 2011-2022 走看看