### [Solved] How to display percentage in query

Posted:

**Tue Sep 17, 2019 9:52 pm**Hi all,

How does one incorporate percentages in aggregate function or sub query

For some demographic data I use a standard aggregate query

which returns number of friends, number of professionals, number of family members etc

for this as well as my age distribution query I would like to show a percentage next to the count, but have no idea of how to go about it.

This is the age distribution query

Any pointers would be very much appreciated.

How does one incorporate percentages in aggregate function or sub query

For some demographic data I use a standard aggregate query

- Code: Select all Expand viewCollapse view
`SELECT "ContactType", COUNT( "ContactType" ) FROM "ViewContactsAll" GROUP BY "ContactType" ORDER BY "ContactType" ASC`

which returns number of friends, number of professionals, number of family members etc

for this as well as my age distribution query I would like to show a percentage next to the count, but have no idea of how to go about it.

This is the age distribution query

- Code: Select all Expand viewCollapse view
`SELECT t.age_group, COUNT(*) AS age_count`

FROM

(

SELECT

CASE WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 1 AND 10

THEN '1-10'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 11 AND 20

THEN '11-20'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 21 AND 30

THEN '21-30'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 31 AND 40

THEN '31-40'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 41 AND 50

THEN '41-50'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 51 AND 60

THEN '51-60'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) BETWEEN 51 AND 61

THEN '61-70'

WHEN DATEDIFF(YEAR, "DateOfBirth", CURDATE()) > 70

THEN '71-plus'

ELSE 'No Info'

END AS age_group

FROM "tblContacts"

) t

GROUP BY t.age_group ORDER BY t.age_group

Any pointers would be very much appreciated.