Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating Percent of Total... 1

Status
Not open for further replies.

bubbisthedog

Programmer
Oct 27, 2005
6
US
Hello, all.

I'd like the values in ColB to reflect the ColA values divided by the summation of the values in ColA:

ColA | ColB
3 | 3/21
5 | 5/21
6 | 6/21
7 | 7/21

I can't figure this one out, and I haven't had any luck finding a solution by searching the Web. Could someone please assist me with this?

Thank you in advance,

bubbis
 
Hi bubbis,

select
cola,
cola / (select sum(cola) from tab)
from tab

Maybe you have to do a typecast to float/decimal if cola is an integer.


Another solution using SQL:1999 OLAP functions in Teradata/Oracle/DB2:

select
cola,
cola / (sum(cola) over ())
from tab

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top