Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sub Query
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00886842
Message ID:
00886906
Views:
24
Troy,

Small correction. In order to get the most recent 5 dates you've to sort by date descending.
SELECT DISTINCT mt1.name,
  (SELECT COUNT(*) FROM
	(SELECT TOP 5 * FROM maytable mt2 
            WHERE mt2.name = mt1.name 
            ORDER BY date DESC) dt2
     WHERE dt2.status = 'somestatus')
  FROM maytable mt1
>Thanks! Perfect for untested code. I did not think they invented neural interfaces yet, where did you get yours?
>
>Troy
>
>>Try (not tested)
SELECT DISTINCT mt1.name,
>>		(SELECT COUNT(*) FROM
>>			(SELECT TOP 5 * FROM maytable mt2 WHERE mt2.name = mt1.name) dt2
>>				WHERE dt2.status = 'somestatus')
>>	FROM maytable mt1
>>>Having a table:
>>> name, status, date
>>>
>>>How can I get the count of a particular status from the most recent 5 entries (date) for each name? This needs to be a single SQL statement that is passed to SQL Server.
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform