How many different people are over 40?
select count(distinct name) from person where age > 40
How about under?
select count(distinct name) from person where age < 40
How many are male?
select count(distinct name) from person where age < 40 and gender = 'male'
What is the count under 40 for each gender?
select count(*), gender from person where age < 40 group by gender