I need help in writing a query to return distinct emails that have not logged into ABC database in the past 5 months. The exact task I have been asked is as following:
Create a table in ABC database with columns email nvarchar(100) and noticecount int. Name the table Not_loggedinUsers. Create a script that finds users that have not logged into ABC within the past 5 months.
If the email address doesn’t exist in Not_loggedinUsers insert the email address into Not_loggedinUsers and set noticecount to 1. If email address exists, increment noticecount by 1. If noticecount = 3, do not increment noticecount.
Note: I also have a table in ABC database called users that has UserID, Username, UserEmail columns, just in case it needs to be joined or for more info. Please let me know if the question is not clear I can provide more details.