假設(shè)數(shù)據(jù)表table中有個(gè)字段modifytime的類型為datetime類型或者TIMESTAMP類型
查詢當(dāng)天的數(shù)據(jù)
select * from table where to_days(modifytime) = to_days(now());
查詢前n天的數(shù)據(jù)
select * from table where to_days(now()) – to_days(modifytime) <= n;
假設(shè)數(shù)據(jù)表匯總有個(gè)字段modifytime的類型為int(5)類型,則:
查詢當(dāng)天的數(shù)據(jù)
select * from table where date_format(from_UNIXTIME(modifytime),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d');
select * from table where to_days(date_format(from_UNIXTIME(modifytime),'%Y-%m-%d')) = to_days(now());