I want to get the sum of group A and B separately, and divide each by the total sum.
I tried to use this:
select name, sum(qt) from ntbl group by name
Result should be as:
You can combine aggregate and window functions together:
select name , sum(qt) as sum_qt , sum(qt) / sum(sum(qt)) over () * 100 as pct_qt from t group by name
Answered By – Salman A
Answer Checked By – Marilyn (BugsFixing Volunteer)