Question

Having a problem with the following Query. i have a device table which logs devices founds in an area, along with a venue_id and a date-timestamp. I'm trying to get all devices in a venue from a given day, month and year, however only devices found after 12pm on that day, and before 12pm the next day. I've tried this, which is the closest i've got.

SELECT COUNT( DISTINCT (mac) ) AS devices,

EXTRACT( DAY FROM DATE_ADD(date_time, INTERVAL 12 HOURS) ) AS day

FROM detected_devices
WHERE venue_id = 1

AND EXTRACT( MONTH FROM DATE_ADD(date_time, INTERVAL 12 HOURS) ) = 12

GROUP BY day
ORDER BY day ASC

This doesn't work, and gives me the following error.

 #1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'FROM detected_devices WHERE client_id = 11 AND venue_id = 1 AND EXTRACT( MONTH F' at line 2
Was it helpful?

Solution

I think you need 'HOUR' instead of 'HOURS' as the unit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top