Q
Problem solve Get help with specific problems with your technologies, process and projects.

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.

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 last published in February 2004

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close