Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting sub category count
Message
 
 
À
07/02/2016 00:43:42
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2014
OS:
Windows 8.1
Network:
Windows 2008 Server
Divers
Thread ID:
01631008
Message ID:
01631027
Vues:
50
>>So, do you want to count all subcategories or just top level subcategories? In the former case we're talking about recursive CTE.
>
>The initial purpose was to count, from a parent, the number of first level child. The SQL select command I provided in the other message sums it all. I basically added a COUNT(*) with a LEFT JOIN. It is just that this forces me to MIN() all the extra fields I want or to switch into a sub select as you mention.

To only get first level subcategories count:
SELECT Category.Numero, Category.Anglais, ISNULL(SubC.Compte,0) as Compte
 FROM Category
OUTER APPLY (select count(*) as Compte from Category AS Category2 
where Category.Numero=Category2.NoCategory) SubC
 WHERE Category.NoClient=78 AND Category.NoCategory=0
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform