"Andreas" <[EMAIL PROTECTED]> writes: > Example: > > Fruit Count % > -------------------------- > Bananas 5 10% > Apples 15 30% > Oranges 30 60%
select fruit_name, count(*), round(count(*)::numeric / (select count(*) from basket) * 100, 0)::text||'%' as "%" from basket group by fruit_name order by "%"; fruit_name | count | % ------------+-------+----- Bananas | 5 | 10% Apples | 15 | 30% Oranges | 30 | 60% (3 rows) -- Gregory Stark EnterpriseDB http://www.enterprisedb.com ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend