How to write a query suitable for generating an age pyramid like this:

I have a table with a DATE field containing their birthday and a BOOL field containing the gender (male = 0, female = 1). Either field can be NULL.
I can’t seem to work out how to handle the birthdays and put them into groups of 10 years.
EDIT:
Ideally the X axis would be percent rather than thousands 🙂
-1in age means0-4,0means4-14etc.This query may leave gaps if there are no persons within a given age group.
The same with percents (from total population):