mysql如何查询一天内的数据

mysql查询一天内的数据方法:1、查询今天的【select * from 表名 where to_days(时间字段名)= to_days(now(} U ? - d + I 7))】;2、查询昨天的【SELECT * FROM 表名 WHERE TO_DAYS】。

mysql如何查询一天内的数据

mysql查询一天内的数- : e 6 .据的方法

今天

select * from 表名 where to_days(时间字段名) = to_days(now());

昨天

SELECT * FROM 表名 WHERE TO_DAW # ^  .YS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1

近7天; ^ @ J e S c

SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTE2 n |RVAL 7 DAY) <= date(时间字段名)

近30天

SELECT * FROMc x 7 1 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名S R H)

本月

SELECT * FROM 表名Z H = 3   s WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( C- G 8 D uURDATE( ) , 's  6 T U%Y%m' )

上一月

SELECT * FROM 表名 WHEREK K # p PERIOD_DIFF( date_format7 q B 1 p( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =1

查询本季度数据

select * from `ht_inS X 3 Z G D } ; Jvoice_information` where Qp N t &UARTER(create_date)=QUARTER(now());

查询上季度数据

select * frA b l _ r K 9 4 Jom `ht_invoice_information` where QUARTER 2 4 | #(create_date)=QUARTER(DATE_SUB(now(),inv w I | 4 v Lterval 1 QUARTER));

查询本年数据

select * from `ht_invoice_informatL = ! ? 5 E W { ]ion` where YEAR(creatd 7 c ` F o  $ `e_date)=YEAR(o i z n PNOW())G x G V x Z h *;

查询上年数据

select * from `ht_invoice_information` where year(create% t E U f ` -_date)=year(date_sub(now(),interval 1 yearv : 4 P @ W J e));

查询当前这周的数据

SELECT name,submittime FROM enterprise WHERE YEARWEE8 ~ T : KK(date_format(subv n 9mittime,'%Y-%m-%d')) = YEARWEEK(now());

查询上周的数据

SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;

查询上个月的数据

select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdj j a Sate(), INTERVAL 1 MONTH),'%7 6 E W jY-%m')
select * from uc i Dser where DATE_F0 ! i q BORMAT(pudate,'%Y%m') = DATE_FORMAT(CUx ? j FRDATE(),'%Y%m') ;
select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,r Q E Z .  - !'%y-%mx 2 9 ( p n Z Y-%d')) = WEEKOFYEAR(now())
select * from user where MONTH(FROM_b u } h l R 8UNIXTIME(pudate,'%y-%m-%d')) = MONTH(now())
select * from user whL 3 9 $ = t ` Vere YEAR(FROM_UNIXTIME(pudate,i  x'%y-%m-%d'))U e @ = YEAR(now()) and MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d')) = MONTH(now())
select * from user wher* 4 5 ee pudate between  上月最后一天  and 下月第一天

查询当前月份的数据

select name,submittime from enterprise   where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')

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

select name,submittime from enterprise where sM | +ubmittime betB X B V @ween date_sub(now(),G 3 z c tinterval 6 month) and now();

相关免费学习推荐:mysql数据库(视频)

以上就是mysql如4 r 8 f t = m .何查询一. @ y ( |天内的数o q W据的详细内容。