《Mysql必讀mysql時(shí)間查詢語(yǔ)句實(shí)例》要點(diǎn):
本文介紹了Mysql必讀mysql時(shí)間查詢語(yǔ)句實(shí)例,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
mysql時(shí)間查詢語(yǔ)句:
?MYSQL學(xué)習(xí)
--本日
select * from 表名 where to_days(時(shí)間字段名) = to_days(now());MYSQL學(xué)習(xí)
--昨天
SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 光陰字段名) <= 1MYSQL學(xué)習(xí)
--7天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(光陰字段名)MYSQL學(xué)習(xí)
--近30天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(光陰字段名)MYSQL學(xué)習(xí)
--本月
SELECT * FROM 表名 WHERE DATE_FORMAT( 光陰字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )MYSQL學(xué)習(xí)
--上一月
SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 光陰字段名, '%Y%m' ) ) =1MYSQL學(xué)習(xí)
#查詢本季度數(shù)據(jù)
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now());
#查詢上季度數(shù)據(jù)
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));
#查詢今年數(shù)據(jù)
select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW());
#查詢上年數(shù)據(jù)
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));MYSQL學(xué)習(xí)
--查詢當(dāng)前這周的數(shù)據(jù)
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());MYSQL學(xué)習(xí)
--查詢上周的數(shù)據(jù)
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;MYSQL學(xué)習(xí)
--查詢當(dāng)前月份的數(shù)據(jù)
select name,submittime from enterprise?? where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')MYSQL學(xué)習(xí)
--查詢距離當(dāng)前現(xiàn)在6個(gè)月的數(shù)據(jù)
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();MYSQL學(xué)習(xí)
--查詢上個(gè)月的數(shù)據(jù)
select name,submittime from enterprise?? where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
select * from ` user ` where DATE_FORMAT(pudate, ' %Y%m ' ) = DATE_FORMAT(CURDATE(), ' %Y%m ' ) ;MYSQL學(xué)習(xí)
select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = WEEKOFYEAR(now())MYSQL學(xué)習(xí)
select *
from user
where MONTH (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = MONTH (now())MYSQL學(xué)習(xí)
select *
from [ user ]
where YEAR (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = YEAR (now())
and MONTH (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = MONTH (now())MYSQL學(xué)習(xí)
select *
from [ user ]
where pudate between 上月最后一天
and 下月第一天
where?? date(regdate)?? =?? curdate();MYSQL學(xué)習(xí)
select?? *?? from?? test?? where?? year(regdate)=year(now())?? and?? month(regdate)=month(now())?? and?? day(regdate)=day(now())
SELECT date( c_instime ) ,curdate( )
FROM `t_score`
WHERE 1
LIMIT 0 , 30MYSQL學(xué)習(xí)
mysql光陰查詢函數(shù)實(shí)例
MySql光陰查詢總結(jié)
mysql光陰查詢函數(shù) mysql光陰戳MYSQL學(xué)習(xí)
維易PHP培訓(xùn)學(xué)院每天發(fā)布《Mysql必讀mysql時(shí)間查詢語(yǔ)句實(shí)例》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/11586.html