Posted by Steve on 10/25/05 13:34
> I need to sort some values by percentage, and don't know how...
Let MySQL do the work for you:
SELECT @TOT:=SUM( `usage` )
FROM mytable
and in the same session, calculate all the percentages and return just
the first one:
SELECT `usage`, `usage` / @TOT AS `perc`
FROM mytable
ORDER BY `perc`
LIMIT 1
No need to learn about arrays just yet 8-)
---
Steve
Navigation:
[Reply to this message]
|