By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Selecting values and their corresponding percentages

P: n/a
Hi,

I have a 5 row table with the following values.

key value
1 5
2 10
3 15
4 15
5 5

I wish to select the values, and their relative percentages, ie, the
result should be:

value percentage
5 10
10 20
15 30
15 30
5 10

I am able to do it with the following SQL query, but is there a better
way to do it (maybe by using only one select statement)?

select
value,
100*(value/total.total) as percentage
from
test,
(
select
sum(value) as total
from
test
) total

Thanks,
Avinash
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.