Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the count of CTE
Message
De
12/10/2021 19:40:55
 
 
À
12/10/2021 17:18:22
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01682503
Message ID:
01682505
Vues:
35
That works when all the records from the CTE is based on one client. Now, I have added more records in the CTE coming from various clients. In my case, I need the get the count based on a condition for one specific client.

For example, lets say I have grouped by months the number of sales for each client. This could be the result of the CTE :

2019-06-01 ClientA 1
2019-07-01 ClientA 2
2019-08-01 ClientA 4
2019-09-01 ClientA 0
2019-10-01 ClientA 6
2019-06-01 ClientB 2
2019-07-01 ClientB 2
2019-08-01 ClientB 3
2019-09-01 ClientB 1
2019-10-01 ClientB 2

In the subquery, one of the formulas needs to divide the sum of all the sales for a client by the count of the number of records for that client. Thus, ClientA needs to divide 13 by 5 because 1+2+4+0+6 equals 13 and we have 5 records from ClientA in the CTE.

Any proper approach to suggest?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform