我的日期查询有什么问题吗?

发布于 2024-10-06 14:42:38 字数 695 浏览 3 评论 0原文

以下查询有问题。我有一个设备表,用于记录在某个区域中找到的设备,以及场地 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野却迷人 2024-10-13 14:42:38

我认为你需要 'HOUR'而不是“HOURS” 作为单位。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文