Three consecutive days
How can I find out if a person has called more than three times in three consecutive days? The call table just keeps note of the person who called and on what date.

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

This is just another example of one of the many fine short questions that occasionally get submitted to Ask The Expert. A short question is best because it allows for leeway, even creativity, in interpreting the requirements.

For instance, which three consecutive days? Let's arbitrarily choose the three days prior to today, because today's not over yet (and the person may yet still call). Furthermore, if the person called six times yesterday, but not at all in the two days before yesterday, does that count? Let's arbitrarily say that there must be at least one call per day.

Finally, let's note that there have to be more than three calls in total.

Here's the solution:

select person_name
     , count(*)    as callcount
  from calls
 where calldate 
    >= current_date - interval '3' day
   and calldate 
     < current_date 
group
    by person_name
having count(distinct calldate) = 3
   and count(*) > 3

For More Information


This was first published in February 2004

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.