Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting the count of CTE
Message
From
12/10/2021 19:40:55
 
 
To
12/10/2021 17:18:22
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01682503
Message ID:
01682505
Views:
34
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform