Hey guys. I have a select statement that retrieves customer activity. What I want the result to display is each active company in a specified timeframe.
Currently when I do a group by on the result (so that it only shows each company once) the date value has the 1st login instead of the most recent...
Here is the statement so far.
Currently outputs:
Account Login
-----------------
Angie's List 6/29/2006
David Stollmack 6/28/2006
Bill Corbin 6/28/2006
Gatesville Country Store 6/27/2006
Each of these accounts have logged in the last few days... so I really need to show that.
Any help would be greatly appreciated!!
Currently when I do a group by on the result (so that it only shows each company once) the date value has the 1st login instead of the most recent...
Here is the statement so far.
Code:
SELECT account.company, date_format(session.last_activity, '%c/%e/%Y') as last_active
FROM account, session, user
WHERE session.user_id !=0
AND session.user_id = user.user_id
AND user.account_id = account.account_id
AND DATE_SUB( CURDATE() , INTERVAL 30 DAY) <= session.last_activity
GROUP BY account.company
ORDER BY session.last_activity DESC
Currently outputs:
Account Login
-----------------
Angie's List 6/29/2006
David Stollmack 6/28/2006
Bill Corbin 6/28/2006
Gatesville Country Store 6/27/2006
Each of these accounts have logged in the last few days... so I really need to show that.
Any help would be greatly appreciated!!