zoukankan      html  css  js  c++  java
  • mysql查询当天数据(上周、本月、上个月、距离当前现在6个月的数据)

    ------------------原文: http://blog.csdn.net/u012157032/article/details/73658155

    下面的ew在实际项目中我因为框架的原因我用了o,

    所以按具体情况而定, 如果查询昨天的数据的话就减一,如:

    $sql .= " AND date(o.date_added) = curdate()-1";

    --------------查"当天"的数据-----------------

    SELECT ew.orderid, ew.carid, ew.userid, ew.`status`, ew.reservetime, ew.starttime, ew.endtime, ew.canceltime, eu.nickname, ec.plateid FROM evlib_workorder ew LEFT JOIN evlib_user eu ON eu.userid = ew.userid LEFT JOIN evlib_car ec ON ec.carid = ew.carid WHERE date(ew.reservetime) = curdate() ORDER BY ew.reservetime DESC;

    --------------查"上周"的数据-----------------

    SELECT ew.orderid, ew.carid, ew.userid, ew.`status`, ew.reservetime, ew.starttime, ew.endtime, ew.canceltime, eu.nickname, ec.plateid FROM evlib_workorder ew LEFT JOIN evlib_user eu ON eu.userid = ew.userid LEFT JOIN evlib_car ec ON ec.carid = ew.carid WHERE YEARWEEK(date_format(ew.reservetime, '%Y-%m-%d')) = YEARWEEK(now()) - 1 ORDER BY ew.reservetime DESC;

    --------------查"本周"的数据-----------------

    SELECT ew.orderid, ew.carid, ew.userid, ew.`status`, ew.reservetime, ew.starttime, ew.endtime, ew.canceltime, eu.nickname, ec.plateid FROM evlib_workorder ew LEFT JOIN evlib_user eu ON eu.userid = ew.userid LEFT JOIN evlib_car ec ON ec.carid = ew.carid WHERE YEARWEEK(date_format(ew.reservetime, '%Y-%m-%d')) = YEARWEEK(now()) ORDER BY ew.reservetime DESC;

    --------------查"本月""当前月"的数据-----------------

    SELECT ew.orderid, ew.carid, ew.userid, ew.`status`, ew.reservetime, ew.starttime, ew.endtime, ew.canceltime, eu.nickname, ec.plateid FROM evlib_workorder ew LEFT JOIN evlib_user eu ON eu.userid = ew.userid LEFT JOIN evlib_car ec ON ec.carid = ew.carid WHERE date_format(ew.reservetime,'%Y-%m')=date_format(now(),'%Y-%m') ORDER BY ew.reservetime DESC;

    --------------查"上个月"的数据-----------------

    SELECT ew.orderid, ew.carid, ew.userid, ew.`status`, ew.reservetime, ew.starttime, ew.endtime, ew.canceltime, eu.nickname, ec.plateid FROM evlib_workorder ew LEFT JOIN evlib_user eu ON eu.userid = ew.userid LEFT JOIN evlib_car ec ON ec.carid = ew.carid WHERE date_format(ew.reservetime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m') ORDER BY ew.reservetime DESC;

    --------------查"距离当前现在6个月"的数据-----------------

    SELECT ew.orderid, ew.carid, ew.userid, ew.`status`, ew.reservetime, ew.starttime, ew.endtime, ew.canceltime, eu.nickname, ec.plateid FROM evlib_workorder ew LEFT JOIN evlib_user eu ON eu.userid = ew.userid LEFT JOIN evlib_car ec ON ec.carid = ew.carid WHERE ew.reservetime between date_sub(now(),interval 6 month) and now() ORDER BY ew.reservetime DESC;

  • 相关阅读:
    PHP数组创建的的两种办法
    Apache配置文件(httpd.conf)的语法检查
    Apache的配置文件,使用了自己的目录,添加了别名的使用
    Apache2.4虚拟主机+别名配置
    margin外边距合并详解
    资源文件res中各种标签的使用
    http://119.145.255.64:10010/repositories/
    一个App的整个流程
    网页快捷键的使用
    oracle 日期字段的处理
  • 原文地址:https://www.cnblogs.com/hjjun/p/8303563.html
Copyright © 2011-2022 走看看