Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sub Query
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00886842
Message ID:
00886906
Vues:
25
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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform