我有一个包含以下字段的数据表
EventID : Int, AutoIncrement, Primary Key
EventType : Int ' Defines what happened
EventTimeStamp : DateTime ' When the Event Happened
UserID : Int ' Unique
查询需要告诉我在整个集合中每天有多少事件发生了新的 UserID。因此,对于每一天,有多少事件的 UserID 在任何前一天都不存在。我已经尝试了很多,而且我每天可以获得唯一用户,但无法弄清楚如何每天获得"new"用户。
最佳答案
Select count(EventId) from table
where
UserId
not in (select UserId from table where EventTimeStamp < now() - interval 1 day)
关于MySQL查询-每天查找 "new"个用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4422827/