Split Percentage based on total.

Database

Split Percentage based on total.

Hi Experts,

Can you please advise, how can i achieve the % column in teradata. 

ORGANIZATION_CODE PRODUCT_FAMILY Sum(SH_SHIPPED_QUANTITY) QUARTER_NAME Split Org % 
A C4500 300 Q1 FY2014 41.60888
B C4500 421 Q1 FY2014 58.39112
A C4500 156 Q1 FY2015 57.77778
B C4500 114 Q1 FY2015 42.22222

Regards,

Sreeni

1 REPLY
Teradata Employee

Re: Split Percentage based on total.

Hi Sreeni,

try something like this (has to be tested):

select organization_code, product_family, the_sum, quarter_name, 

         the_sum * 100.00 / nullifzero ( sum(the_sum) over (partition by quarter_name /* and other columns of your choice */) ) as percentage

from (

                 select organization_code, product_family, sum(sh_shipped_quantity) as the_sum, quarter_name

                 from the_table

                 group by organization_code, product_family, quarter_name

) t

Regards,

Vlad.