Skip to content
Advertisement

SQL query to get sum of headcount according to column grouping

The below query is used to find out the headcount of employees in a particular department. This is working fine-

The output looks like –

Now I want to calculate the sum in the same query at the division and district level. i.e. sum of headcounts(JAN Column) per district and per division in the same query. Is this possible ?

The output should look like –

so from above output- sum of division should be sum of all headcounts in one division (CA Division and US Division) and sum of district should be for Deer district – 1+0=1 for Neuquen district 101+3=104 like that.

Advertisement

Answer

Instead of 1 measure:

Use 3 measures:

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