我的日期查询有什么问题吗?
以下查询有问题。我有一个设备表,用于记录在某个区域中找到的设备,以及场地 ID 和日期时间戳。我试图获取特定日期、月份和年份内场地中的所有设备,但仅找到当天中午 12 点之后和第二天中午 12 点之前找到的设备。我已经尝试过这个,这是我最接近的。
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
这不起作用,并给我以下错误。
#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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你需要 'HOUR'而不是“HOURS” 作为单位。
I think you need 'HOUR' instead of 'HOURS' as the unit.