我的数据库按以下方式设置
date DATETIME
event VARCHAR(10)
以下是数据样本
[2016-03-20 12:00:00] [event1]
[2016-03-20 12:00:00] [event2]
[2016-03-20 12:00:00] [event3]
[2016-03-20 12:01:00] [event1]
[2016-03-20 12:01:00] [event8]
[2016-03-20 12:01:00] [event6]
我试图在一个未知时间点匹配多个事件
例如,如果event1,event2,event3同时发生,我想匹配并分组返回日期的日期
Match found at [2016-03-20 12:00:00]
我曾尝试编写一些代码,但说实话,我的sql知识非常有限
SELECT log.date
FROM eventlog log
INNER JOIN eventlog e
ON(log.date = e.date)
WHERE e.event = 'event1'
OR e.event = 'event2'
OR e.event = 'event3'
GROUP BY log.date
任何帮助将不胜感激
答案 0 :(得分:0)
试试这个:
SELECT `date` FROM eventlog
GROUP BY `date`
HAVING COUNT(DISTINCT event) = 3