You can use the HOUR () function:
SELECT * FROM 'table' WHERE HOUR(`updatetime`) = 9
Alas, this query performance will be terrible as soon as you go to a few thousand rows - the functions are not indexed, so every time this query is run, a full table scan will be performed.
What we did in a similar situation: we created another updatetime_hour column, indexed it and filled it in (and updated it when updating); then the request becomes fast:
SELECT * FROM 'table' WHERE `updatetime_hour` = 9
Yes, we have denormalized the data and this is a bit more of a household, but I have yet to see a faster solution. (We reviewed and measured insert and update triggers to populate updatetime_hour from updatetime , but decided against performance, see if they are useful to you.)
Piskvor
source share