2
我有以下查詢:檢查最後更新時間大於10分鐘
SELECT * FROM event_incidents order by last_update desc limit 1;
我想要的是讓第一行,並檢查是否在該行的LAST_UPDATE時間是大於10分鐘當前時間。
我有以下查詢:檢查最後更新時間大於10分鐘
SELECT * FROM event_incidents order by last_update desc limit 1;
我想要的是讓第一行,並檢查是否在該行的LAST_UPDATE時間是大於10分鐘當前時間。
你可以嘗試這樣的:
select * from event_incidents
where last_update >= (NOW() - INTERVAL 10 MINUTE)
ORDER BY last_update desc
LIMIT 1;
爲此,您可以用聚集和在where
的比較。如果您有last_update
指數則:
SELECT (case when MAX(last_update) >= date_sub(now(), interval 10 minute)
then 'recent'
else 'ancient'
end)
FROM event_incidents ;
我不知道你想回到什麼,所以我提出了「最近」和「古」。
注:
如果你只是想返回上一個單行標誌:
SELECT ei.*,
(last_update > date_sub(now(), interval 10 minute)) as RecencyFlag
FROM event_incidents
ORDER BY last_update desc
LIMIT 1;
你的問題是模糊的。你應該包括你想要*返回*。這是什麼意思「檢查」? –
對不起,我太模糊了,我想要的是得到第一行,並檢查該行上的last_update時間是否大於當前時間的10分鐘。 –
這就是我的第二個答案。 –