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 
    by person_name
having count(distinct calldate) = 3
   and count(*) > 3

For More Information

Dig Deeper on Oracle and SQL

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.