New to MySql and am trying to query a table to get just certain hours and minutes such as
05:00:00. Have been using following, but only getting the 05:00:00 hours but need both 05 and 11 hours...
SELECT * FROM `UMHMwind`
WHERE Hour(`dt`) = "05,11" AND MINUTE(`dt`) = "0".
Probably a simple solution but have been unable to find anything helpful online.
To specify a list of values, you use the IN
clause :
SELECT * FROM `UMHMwind`
WHERE HOUR(`dt`) IN (5, 11) AND MINUTE(`dt`) = 0
Note that when using functions around dates, indexes will not be used.
The documentation is your friend.
The correct syntax is:
SELECT *
FROM UMHMwind
WHERE Hour(dt) IN (5, 11) AND MINUTE(dt) = 0
Note that the hour()
and minute()
function return integers, so you should compare the results to integers.
You want to check a value is equal to either a value OR another (I mean hours in this case): you can use:
... where HOUR(dt) = 5 or HOUR(dt) = 11 ...
... where HOUR(dt) in (5, 11) ...
The second is a short-hand, so I suggest it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.