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;

  • 相关阅读:
    ERRORCODE=4228, SQLSTATE=null
    DB2和Oracle中唯一约束和唯一索引对比
    SW 3D 样条曲线
    SW 快速操作
    spring依赖注入的方式(一)
    Oracle Connect By的用法
    转:min(x,y)高效算法
    【转】QQ盗号核心编程
    转:理解并解决GBK转UTF8奇数中文乱码
    Oracle数据库的导入和导出命令
  • 原文地址:https://www.cnblogs.com/hjjun/p/8303563.html
Copyright © 2011-2022 走看看