Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique rows per day

I need to get a list of users email addresses that logged into my website over the course of a day.

The list may contain duplicate email addresses but not more than one per day.

I need to obtain this data for a week.

I have a table that contains records for each successful login as follows..

[ID], [LOGIN_EMAIL], [LOGIN_TIME]

The following query gets me the whole data set for the week but I need to filter it to one email address per day and get the entire list for the week?

SELECT LOGIN_EMAIL 
FROM USER_LOGINS 
WHERE LOGIN_TIME IS BETWEEN @STARTDATE AND @ENDDATE
like image 402
carrot_programmer_3 Avatar asked Aug 11 '26 13:08

carrot_programmer_3


1 Answers

SELECT   LOGIN_EMAIL,
         DATEADD(DAY, DATEDIFF(DAY, 0, LOGIN_TIME), 0) AS LOGIN_DATE
FROM     USER_LOGINS 
WHERE    LOGIN_TIME BETWEEN @STARTDATE AND @ENDDATE
GROUP BY LOGIN_EMAIL, 
         DATEADD(DAY, DATEDIFF(DAY, 0, LOGIN_TIME), 0)
like image 109
Mikael Eriksson Avatar answered Aug 13 '26 07:08

Mikael Eriksson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!