我正在尝试在“分钟”字段上加入查询结果 - 这是事件的小时:分钟。我有两个不同的选择查询,我正在尝试 UNION (这可能不对,只是尝试不同的东西,我发现 MySQL 文档很难阅读)。
所以我想要
H:M 然后是 and 的结果addCount
-projectsNum
所以对于每一小时/分钟我都有统计数据。
我哪里错了?
(
SELECT
DATE_FORMAT(`when`, '%H:%i') as `min`,
COUNT(`ipAddress`) AS `addCount`
FROM `metric` m
WHERE `when` BETWEEN DATE_SUB(NOW(), INTERVAL 3 HOUR) AND NOW()
GROUP BY DAY(`when`), HOUR(`when`), MINUTE(`when`)
)
UNION
(
SELECT
DATE_FORMAT(v.`created`, '%H:%i') as `min`,
COUNT(v.`projID`) as `projectsNum`
FROM `projects` v
WHERE v.`created` BETWEEN DATE_SUB(NOW(), INTERVAL 3 HOUR) AND NOW()
GROUP BY DAY(v.`created`), HOUR(v.`created`), MINUTE(v.`created`)
)