Select all rows inserted within the last 24 hours(最近24小時新插入數據):
mysql>SELECT * FROM entries WHERE entry_date > UNIX_TIMESTAMP(NOW()) - 86400;
Select all rows inserted before 12:00am of the current day(當天12點前插入的數據):
mysql>SELECT * FROM entries WHERE date(entry_date) = date(NOW());
Determine the weekday of the most recent entry for a specific user(檢查一個特定——指定用戶最近一天登陸時間——以星期算,也就是某用戶最近一次登陸是星期幾):
mysql>SELECT DAYNAME(MAX(entry_date)) AS day FROM entries WHERE user_id = 22;
MySQL內部函數說明:
UNIX_TIMESTAMP():返回unix時間戳,stamp單詞為郵戳、郵票的意思。
dayname(date):傳回日期的名稱,例如Monday、Sunday
MAX():最大的數
SELECT DAYNAME(MAX(`login_time`)) AS day FROM `Member`(對於更新登陸時間來說,此句就是返回最近一次登陸是星期幾)