Skip to content
Advertisement

How to get row count based on other column groups

I need to count the number of dates with which the invoices are made to certain customers in each month

Consider the table named Table1

I tried the folllowing code

and the result was

The result I need should count the column named branch based on column month, the desired result is

Here rowcount is based on both column branch and Month, how can I get this result?

Advertisement

Answer

You need to partition by month. Something like this:

Note that month is repeated. An order by is needed in SQL Server, so you need something. Other options are:

I suspect the last is what you really want.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement