i have to query data in certain range of date and time. I have a ClearDB database in heroku with 2 fields to save date and time, these fiels are varchar type, not DATE. Data Structure here and don't look the field names, i have changed below in the querys for better understanding.
I have this query that works:
SELECT
DISTINCT dates, times, lat, long, ide FROM data
WHERE ide = 'lcg1234' AND (dates>= '2016-01-27' AND times>='15:00:00')
AND (dates<= '2016-01-29' AND times<='16:00:00')
ORDER BY times ASC
The problem is when i change the time in the last AND to a lower value like this:
SELECT
DISTINCT dates, times, lat, long, ide FROM data
WHERE ide = 'lcg1234' AND (dates>= '2016-01-27' AND times>='15:00:00')
AND (dates<= '2016-01-29' AND times<='01:00:00')
ORDER BY times ASC
It not work, why this happend? any ideas are wellcome! and sorry for my bad english.
You should combine dates and times column and make custom date time field. And then make comparisons.
Check if following query works.
SELECT
DISTINCT dates, times, lat, long, ide FROM data
WHERE ide = 'lcg1234'
AND CONCAT(`dates`,' ',`times`) >= '2016-01-27 15:00:00'
AND CONCAT(`dates`,' ',`times`) <= '2016-01-29 01:00:00'
ORDER BY times ASC
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.