1. 程式人生 > >mysql查詢當天(今天)的資料

mysql查詢當天(今天)的資料

--------------查"當天"的資料----------------- 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;