Skip to content
Advertisement

SQL query to get child count and sum it

My table is kind of like :

the result I am trying to get is :

So the SUB_CODE_COUNT is the sum count of each unique SUB_CODE, and CODE_COUNT is the sum count of all SUB_CODE for that CODE

This what I have right now:

Result:

Advertisement

Answer

Use analytic functions:

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