i need to select only full hour values from a list of datetime entries.
But if i select more columns, the group by hour doesn’t work.
So if i don’t select the column "datetime" the group by works.
SELECT
datetime,
DATE_FORMAT(STR_TO_DATE(datetime, " %Y_%m%d_%H%i%s"), '%H')
FROM imagedata
WHERE DIRECTORY = 17082901
and `datetime` >= '2017_0721_000000'
and `datetime` <= '2017_0921_131500'
GROUP BY datetime, DATE_FORMAT(STR_TO_DATE(datetime, " %Y_%m%d_%H%i%s"), '%H')
Example: https://www.db-fiddle.com/f/iaNrxC35uFYhDNZSeXa76A/1
Example Data:
directory datetime year mo day time
17082901 2017_0829_200000 2017 8 29 200000
17082901 2017_0829_200700 2017 8 29 200700
17082901 2017_0829_201500 2017 8 29 201500
17082901 2017_0829_203000 2017 8 29 203000
17082901 2017_0829_204500 2017 8 29 204500
17082901 2017_0829_205100 2017 8 29 205100
17082901 2017_0829_210000 2017 8 29 210000
...
I need a result like this:
29.08.17 20:00
29.08.17 21:00
...
2
Answers
Here is a good solution i think:
Try this:
If you want to select all fields: