Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Count occurrences in sequence with SQL?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01147939
Message ID:
01147967
Views:
15
Chris,

After re-reading your post, I think one of these two options is more in line with what you're after:
SELECT COUNT(DISTINCT date_fld) AS day_count
	FROM Table_Name
	WHERE date_fld >
		(SELECT date_fld
			FROM Table_Name
			WHERE value_fld <> 'A')
SELECT date_fld, COUNT(*) AS rows
	FROM Table_Name
	GROUP BY date_fld
	HAVING date_fld >
		(SELECT date_fld
			FROM Table_Name
			WHERE value_fld <> 'A')
	ORDER BY date_fld
HTH,
Chad


>Chris,
>
>How 'bout something like this:
>
>SELECT date_fld, COUNT(*) AS rows
>	FROM Table_Name
>	GROUP BY date_fld
>	HAVING date_fld NOT IN
>		(SELECT date_fld
>			FROM Table_Name
>			WHERE value_fld <> 'A')
>	ORDER BY date_fld
>
>HTH,
>Chad
>
>
>I have a table with multiple records per date, and I need to know the number of days in order, for which all occurances equal a given value. I've found a few half answers, but they're not adding up to a whole.
>>
>>
>>8/21   A
>>8/21   P
>>8/22   A
>>8/22   A
>>8/23   A
>>8/23   A
>>
>>
>>For the above data, I need to compute the number of days (counting backwards) where all results = "A", while not counting the 8/21 "A" - EG: 2. I've got a object.method that will do it, but I'd prefer an SQL solution rather than SCANning the table and calling the method.
_________________________________
There are 2 types of people in the world:
    Those who need closure
Previous
Reply
Map
View

Click here to load this message in the networking platform