mysql查询去年本月的数据_MySQL查询本周、上周、本月、上个月份数据的sql代码...
MySQL查詢的方式很多,下面為您介紹的MySQL查詢實現(xiàn)的是查詢本周、上周、本月、上個月份的數(shù)據(jù),如果您對MySQL查詢方面感興趣的話,不妨一看
..查詢當(dāng)前這周的數(shù)據(jù)
SELECT?name,submittime?FROM?enterprise?WHERE?YEARWEEK(date_format(submittime,'%Y-%m-%d'))?=?YEARWEEK(now());
查詢上周的數(shù)據(jù)
SELECT?name,submittime?FROM?enterprise?WHERE?YEARWEEK(date_format(submittime,'%Y-%m-%d'))?=?YEARWEEK(now())-1;
查詢當(dāng)前月份的數(shù)據(jù)
select?name,submittime?from?enterprise?where?date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
查詢距離當(dāng)前現(xiàn)在6個月的數(shù)據(jù)
select?name,submittime?from?enterprise?where?submittime?between?date_sub(now(),interval?6?month)?and?now();
查詢上個月的數(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')?;
select?*?from?user?where?WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d'))?=?WEEKOFYEAR(now())
select?*
from?user
where?MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d'))?=?MONTH(now())
select?*
from?[user]
where?YEAR(FROM_UNIXTIME(pudate,'%y-%m-%d'))?=?YEAR(now())
and?MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d'))?=?MONTH(now())
select?*
from?[user]
where?pudate?between?上月最后一天
and?下月第一天
總結(jié)
以上是生活随笔為你收集整理的mysql查询去年本月的数据_MySQL查询本周、上周、本月、上个月份数据的sql代码...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php语录网站,杨泽业:给你的wordp
- 下一篇: python数据结构中文版_Python