MySQL query - finding new users per day

I have a data table with the following fields

EventID        : Int, AutoIncrement, Primary Key
EventType      : Int                             ' Defines what happened
EventTimeStamp : DateTime                        ' When the Event Happened
UserID         : Int                             ' Unique

The request should tell me how many events happened with the new user IDs for each day in the entire set. So, for each day, how many events exist that have a UserID that does not exist on the previous day. I tried a lot, and I can get unique users per day, but I can’t figure out how to get “NEW” users per day.

+5
source share
5 answers

Thank you all for your help. I voted for help. Here is what I did:

2 ( , 2, , ).

:

select min(to_days(`Events`.TimeStamp)) AS Day0,
    `Events`.TimeStamp AS TimeStamp,
    `Events`.UserID AS UserID
from `Events` group by `Events`.UserID order by `Events`.UserID

NewUsers:

select count(distinct Sightings.UserID) AS Count,
    date(Sightings.TimeStamp) AS Date from Sightings
    group by date(Sightings.TimeStamp)
+1
. , , :

SELECT, EventTimeStamp MIN(EventTimeStamp) , SELECT , MIN (, GROUP BY UserID).

+1
Select count(EventId) from table
where 
UserId 
  not in (select UserId from table where EventTimeStamp < now() - interval 1 day)
+1

First get a table bfor each user when he first arrived, then attach this table to get all the events for that user for that day.

SELECT DATE(a.EventTimeStamp), COUNT(*) FROM table a
JOIN
(SELECT MIN(EventTimeStamp) AS EventTimeStamp, UserID from table group by userID) b
ON a.UserID = b.UserID
AND DATE(a.EventTimeStamp) = DATE(b.EventTimeStamp) 
GROUP BY DATE(a.EventTimeStamp) 
+1
source

86400- (EventTimeStamp) as new_users

0
source

All Articles