Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 680183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:20:37+00:00 2026-05-14T01:20:37+00:00

Got a problem with a query I’m trying to write. I have a table

  • 0

Got a problem with a query I’m trying to write. I have a table that lists people that have been sent an email. There is a bit column named Active which is set to true if they have responded. But I need to count the number of consecutive emails the person has been inactive since either their first email or last active email.

For example, this basic table shows one person has been sent 9 emails. They have been active within two of the emails (3 & 5). So their inactive count would be 4 as we are counting from email number 6 onwards.

PersonID(int)    EmailID(int)    EmailDate(datetime)    Active(bit)
1                1               2009-07-18 19:56:20    0
1                2               2009-08-18 19:56:20    0
1                3               2009-09-18 19:56:20    1
1                4               2009-10-18 19:56:20    0
1                5               2009-11-18 19:56:20    1
1                6               2009-12-18 19:56:20    0
1                7               2010-01-18 19:56:20    0
1                8               2010-02-18 19:56:20    0
1                9               2010-03-18 19:56:20    0

Any pointers or help would be great.

Regards
Greg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:20:37+00:00Added an answer on May 14, 2026 at 1:20 am

    My first cut:

    SELECT PersonID, COUNT(*) FROM Table T1
    WHERE Active = 0 AND EmailDate > 
       (SELECT MAX(EMailDate) FROM Table T2 
           WHERE T2.PersonID = T1.PersonID AND Active = 1)
    GROUP BY PersonID
    

    Note that this solution requires that each person answers at least one email. If you want to include people who were inactive from the very first email that was sent to them you need to wrap that (MAX(EmailDate)) term inside some kind of IFNULL() returning a date before the start date of the system for NULLs.

    Also, as KM points out below, if someone is not currently inactive (they answered the most recent email) they will not be in the result set. I think that probably meets your needs but, if not, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's been done, a sample BigArray<T> implementation is here. May 16, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer According to Eclipse Packages table, the distro you downloaded (RCP)… May 16, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer $('textarea.txta').elastic(); it'll apply to all textareas having class txta... May 16, 2026 at 6:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I got a problem with Entity Framework 4.0 I have a hierarchical table Category:
I have a query that is very recently starting to throw: The built-in indices
I got a problem with this linq query: from PersistedFileInfo fi in m_Database from
Hey there I got a problem with my code, I compared three ways of
I've got a problem with VB6. I have a form with several ComboBox objects
I've got a problem that keeps coming up with normalized databases and was looking
I've got a problem with NHibernate trying to load a small hierarchy of data.
i got problem with a query, got something like this command.CommandText = SELECT +
I have a query that takes 5 seconds to run in SQL Server Managment
I've got a problem with the removal of entities in my JPA application: basically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.