mysql中時間查詢的資料收集

2021-09-22 13:55:36 字數 579 閱讀 9085

查從昨天起 到一年前的資料 sql

select * from test where  欄位名  between date_sub(now(), interval 365 day) and date_sub(now(), interval 1 day)

通過sql語句查詢與當前時間相隔5分鐘以內的資料

select * from 資料表名 where 欄位名 between date_add(now(), interval - 5 minute) and now();

查詢2011的資料:select * from 表 where year(date)='2011';

查詢月份為12的資料:select * from 表 where month(date)='12';

查詢天數為本年第二天的資料:select * from 表 where dayofyear(date)='2';

我解釋一下:

select * from 表 where 這是必須的

year,month,dayofyear是mysql的函式,分別是取得年,月,和當前時間在本年是第幾天的3個函式

date就是你儲存時間的字段

MYsql 查詢 查詢當前月份的資料(時間 查詢)

mysql查詢的方式很多,下面為您介紹的mysql 查詢實現的是查詢本週 上週 本月 上個月份的資料,如果您對mysql查詢方面感興趣的話,不妨一看。查詢當前這週的資料 select name,submittime from enterprise where yearweek date format...

mysql時間查詢 MySQL按時間查詢

mysql 今天select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days 時間欄位名 1 近7天select from 表名 where date sub curdate int...

Mysql中查詢系統時間的方法

第一種方法 select current date mysql select current date as systemtime systemtime 2009 07 29 第二種方法 select now mysql select now as systemtime systemtime 200...