Click here to get back home

Getting Counts Based on Non-specified date ranges

 HomeNewsGroups | Search | About
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Getting Counts Based on Non-specified date ranges No bother 07-28-2006
Posted by No bother on July 28, 2006, 3:48 pm
Please log in for more thread options
I have a table which has, among other fields, a date field. I want to
get a count of records where certain criteria are met for, say, three
days in a row. For example:

NumWidgets        Date
1                1/1/2000
10                1/2/2000
20                1/3/2000
10                1/4/2000
15                1/5/2000
5                1/6/2000

I would like to know how many times 3 consecutive days have at least 10
widgets. In this case the answer is 1 because from 1/1/2000 to 1/3/2000
one day did not have at least 10 widgets, from 1/2/2000 to 1/4/2000 each
day had at least 10 widgets, from 1/3/2000 to 1/5/2000, though all three
days have at least 10 widgets, 1/3/2000 was already counted before so it
should not count again, and from 1/4/2000 to 1/6/2000 one day did not
have a least 10 widgets. Since 1/3/2000 was not counted before it would
otherwise qualify in the next set.

I am hoping to do this in a query and not have to iterate manually
through the entire table.



Posted by strawberry on July 30, 2006, 7:37 pm
Please log in for more thread options

No bother wrote:
> I have a table which has, among other fields, a date field. I want to
> get a count of records where certain criteria are met for, say, three
> days in a row. For example:
>
> NumWidgets        Date
> 1                1/1/2000
> 10                1/2/2000
> 20                1/3/2000
> 10                1/4/2000
> 15                1/5/2000
> 5                1/6/2000
>
> I would like to know how many times 3 consecutive days have at least 10
> widgets. In this case the answer is 1 because from 1/1/2000 to 1/3/2000
> one day did not have at least 10 widgets, from 1/2/2000 to 1/4/2000 each
> day had at least 10 widgets, from 1/3/2000 to 1/5/2000, though all three
> days have at least 10 widgets, 1/3/2000 was already counted before so it
> should not count again, and from 1/4/2000 to 1/6/2000 one day did not
> have a least 10 widgets. Since 1/3/2000 was not counted before it would
> otherwise qualify in the next set.
>
> I am hoping to do this in a query and not have to iterate manually
> through the entire table.

So, actually you want to select all days where the number of widgets is
less than 10, and then, from that set, count the number of times
that`the number of days between two consecutive dates is greater than 3?


Posted by No bother on July 31, 2006, 12:55 pm
Please log in for more thread options
strawberry wrote:
> No bother wrote:
>> I have a table which has, among other fields, a date field. I want to
>> get a count of records where certain criteria are met for, say, three
>> days in a row. For example:
>>
>> NumWidgets        Date
>> 1                1/1/2000
>> 10                1/2/2000
>> 20                1/3/2000
>> 10                1/4/2000
>> 15                1/5/2000
>> 5                1/6/2000
>>
>> I would like to know how many times 3 consecutive days have at least 10
>> widgets. In this case the answer is 1 because from 1/1/2000 to 1/3/2000
>> one day did not have at least 10 widgets, from 1/2/2000 to 1/4/2000 each
>> day had at least 10 widgets, from 1/3/2000 to 1/5/2000, though all three
>> days have at least 10 widgets, 1/3/2000 was already counted before so it
>> should not count again, and from 1/4/2000 to 1/6/2000 one day did not
>> have a least 10 widgets. Since 1/3/2000 was not counted before it would
>> otherwise qualify in the next set.
>>
>> I am hoping to do this in a query and not have to iterate manually
>> through the entire table.
>
> So, actually you want to select all days where the number of widgets is
> less than 10, and then, from that set, count the number of times
> that`the number of days between two consecutive dates is greater than 3?
>

No. I need to know how many times within the table three consecutive
days each have at least 10 widgets. The problem with first selecting
the days is that I have to use a custom function to filter out holidays
and weekends. I should be able to tell if a given date range is
consecutive for my purposes but I would think that would have to be done
before filtering out other data. Also, I need to make sure I am not
counting any given date twice.


Posted by strawberry on August 1, 2006, 9:23 am
Please log in for more thread options

No bother wrote:
> strawberry wrote:
> > No bother wrote:
> >> I have a table which has, among other fields, a date field. I want to
> >> get a count of records where certain criteria are met for, say, three
> >> days in a row. For example:
> >>
> >> NumWidgets        Date
> >> 1                1/1/2000
> >> 10                1/2/2000
> >> 20                1/3/2000
> >> 10                1/4/2000
> >> 15                1/5/2000
> >> 5                1/6/2000
> >>
> >> I would like to know how many times 3 consecutive days have at least 10
> >> widgets. In this case the answer is 1 because from 1/1/2000 to 1/3/2000
> >> one day did not have at least 10 widgets, from 1/2/2000 to 1/4/2000 each
> >> day had at least 10 widgets, from 1/3/2000 to 1/5/2000, though all three
> >> days have at least 10 widgets, 1/3/2000 was already counted before so it
> >> should not count again, and from 1/4/2000 to 1/6/2000 one day did not
> >> have a least 10 widgets. Since 1/3/2000 was not counted before it would
> >> otherwise qualify in the next set.
> >>
> >> I am hoping to do this in a query and not have to iterate manually
> >> through the entire table.
> >
> > So, actually you want to select all days where the number of widgets is
> > less than 10, and then, from that set, count the number of times
> > that`the number of days between two consecutive dates is greater than 3?
> >
>
> No. I need to know how many times within the table three consecutive
> days each have at least 10 widgets. The problem with first selecting
> the days is that I have to use a custom function to filter out holidays
> and weekends. I should be able to tell if a given date range is
> consecutive for my purposes but I would think that would have to be done
> before filtering out other data. Also, I need to make sure I am not
> counting any given date twice.

So, actually you want to select all days where the number of widgets is
less than 10, and then, from that set, count the number of times
that`the number of days (minus weekends and holidays) between two
consecutive dates is greater than 3?


Posted by No bother on August 1, 2006, 1:17 pm
Please log in for more thread options
strawberry wrote:
> No bother wrote:
>> strawberry wrote:
>>> No bother wrote:
>>>> I have a table which has, among other fields, a date field. I want to
>>>> get a count of records where certain criteria are met for, say, three
>>>> days in a row. For example:
>>>>
>>>> NumWidgets        Date
>>>> 1                1/1/2000
>>>> 10                1/2/2000
>>>> 20                1/3/2000
>>>> 10                1/4/2000
>>>> 15                1/5/2000
>>>> 5                1/6/2000
>>>>
>>>> I would like to know how many times 3 consecutive days have at least 10
>>>> widgets. In this case the answer is 1 because from 1/1/2000 to 1/3/2000
>>>> one day did not have at least 10 widgets, from 1/2/2000 to 1/4/2000 each
>>>> day had at least 10 widgets, from 1/3/2000 to 1/5/2000, though all three
>>>> days have at least 10 widgets, 1/3/2000 was already counted before so it
>>>> should not count again, and from 1/4/2000 to 1/6/2000 one day did not
>>>> have a least 10 widgets. Since 1/3/2000 was not counted before it would
>>>> otherwise qualify in the next set.
>>>>
>>>> I am hoping to do this in a query and not have to iterate manually
>>>> through the entire table.
>>> So, actually you want to select all days where the number of widgets is
>>> less than 10, and then, from that set, count the number of times
>>> that`the number of days between two consecutive dates is greater than 3?
>>>
>> No. I need to know how many times within the table three consecutive
>> days each have at least 10 widgets. The problem with first selecting
>> the days is that I have to use a custom function to filter out holidays
>> and weekends. I should be able to tell if a given date range is
>> consecutive for my purposes but I would think that would have to be done
>> before filtering out other data. Also, I need to make sure I am not
>> counting any given date twice.
>
> So, actually you want to select all days where the number of widgets is
> less than 10, and then, from that set, count the number of times
> that`the number of days (minus weekends and holidays) between two
> consecutive dates is greater than 3?
>
No. To phrase things as closely to your syntax as I can, I actually
want to select all days where the number of widgets is at least 10
(meaning, 10 or more), and then, from that set, count the number of
times that there are 3 consecutive dates, with the provision that a
date counted in one set is not counted in another set. So, if 4
consecutive days have at least 10 widgets each then the count I need is
1, not 2. If six consecutive days have at least 10 widgets each then the
count is 2. If two consecutive days have at least 10 widgets, followed
by a day that did not have at least 10 widgets, which is followed by a
day with at least 10 widgets, then the count is zero.

Similar ThreadsPosted
how to check for date/time ranges within record (check for schedule conflicts) January 20, 2006, 3:18 pm
Two Counts In One Query? June 17, 2005, 10:21 am
Query that counts multiple values February 9, 2007, 8:31 am
Converting VARCHAR "date" info to an actual date field August 15, 2005, 7:49 pm
Web Based Training Options August 4, 2006, 11:16 am
How to determine the size of a set of rows based on a where clause October 17, 2005, 1:14 am
automatically filter records based on a userlogin name?? October 25, 2005, 11:53 am
create a c++ based program using mysql odbc. December 26, 2005, 7:18 am
Filtering resultsets based on GROUP_CONCAT() generated value April 28, 2006, 3:37 pm
ADDDATE based on an integer field in the record February 12, 2007, 9:18 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap