MySQL查询今天、昨天、7天、近30天、本月、上一月 数据

Posted by

 

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

orcal的时间比较

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

<if test=”type ==1″>
and DATE_FORMAT(create_date,’%Y-%m-%d’) =
DATE_FORMAT(now(),’%Y-%m-%d’)
</if>
<if test=”type ==2″>

select * from `ht_invoice_information` where
QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));

<![CDATA[
and DATE_FORMAT(create_date,’%Y-%m-%d’) >=
DATE_FORMAT(#{minDate},’%Y-%m-%d’)
and DATE_FORMAT(create_date,’%Y-%m-%d’) <=
DATE_FORMAT(#{maxDate},’%Y-%m-%d’)
]]>
</if>
<if test=”type ==3″>
and DATE_FORMAT(create_date,’%Y-%m’) =
DATE_FORMAT(CURDATE(),’%Y-%m’)
</if>

查询当前这周的数据

select * from RegulatoryRecord where  regulatorydate <
to_date(‘2018-08-15 15:58:00′,’yyyy-mm-dd hh24:mi:ss’)

select*from`user`whereDATE_FORMAT(pudate,’%Y%m’)=DATE_FORMAT(CURDATE(),’%Y%m’)
;

SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) – TO_DAYS( 时间字段名)
<= 1

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

from [ user ]

FROM `t_score`

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

and下月第一天

select*

SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <=
date(时间字段名)

select name,submittime from enterprise   where
date_format(submittime,’%Y-%m’)=date_format(DATE_SUB(curdate(),
INTERVAL 1 MONTH),’%Y-%m’)

andMONTH (FROM_UNIXTIME(pudate, ‘ %y-%m-%d ‘ ))=MONTH (now())

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

select * from `ht_invoice_information` where
YEAR(create_date)=YEAR(NOW());

查询当前月份的数据

SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, ‘%Y%m’ ) =
DATE_FORMAT( CURDATE( ) , ‘%Y%m’ )

WHERE 1

本月

上一月

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

where pudatebetween上月最后一天

#查询上季度数据

相关文章

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注