Percent of Males and Females and Age distribution

Percent of Males and Females and Age distribution

am 15.02.2006 11:16:43 von fritz-bayer

Hello,

I'm still using the older version of mysql 3.32 and I have a table,
which stores information about people, like their birthdate as a date
and their gender a smallint, which can be 0 meaning male or 1 meaning
female.

I need one select, which will return the percentage of males and
females and then I need a select, which will tell me how many people
are withing their teens, 20ths, 30ths and so on.

Is that even possible without subselects? And how do I get the total
number of rows in a table, disregarding any restrictions in the where
and having clauses?

Fritz

Re: Percent of Males and Females and Age distribution

am 15.02.2006 12:30:05 von Jeff North

On 15 Feb 2006 02:16:43 -0800, in mailing.database.mysql
"fritz-bayer@web.de"
<1139998603.595679.297320@o13g2000cwo.googlegroups.com> wrote:

>| Hello,
>|
>| I'm still using the older version of mysql 3.32 and I have a table,
>| which stores information about people, like their birthdate as a date
>| and their gender a smallint, which can be 0 meaning male or 1 meaning
>| female.
>|
>| I need one select, which will return the percentage of males and
>| females and then I need a select, which will tell me how many people
>| are withing their teens, 20ths, 30ths and so on.
>|
>| Is that even possible without subselects? And how do I get the total
>| number of rows in a table, disregarding any restrictions in the where
>| and having clauses?

Sounds like a crosstab query will do the trick.
http://dev.mysql.com/tech-resources/articles/wizard/index.ht ml

------------------------------------------------------------ ---
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
------------------------------------------------------------ ---

Re: Percent of Males and Females and Age distribution

am 15.02.2006 23:48:00 von Bill Karwin

wrote in message
news:1139998603.595679.297320@o13g2000cwo.googlegroups.com.. .
> I need one select, which will ...

Why does this need to be a single query? Wouldn't it be easier to do this
in several queries, and then use application code to do the final
preparation into a report?

The solution is likely to be a very complex query. How much time will it
take you to develop and test this solution as a single query, versus as a
set of simpler queries?

Who would want to maintain such code? It would be a lot easier to maintain
a set of simpler queries, when the reporting requirements inevitably change.

Just food for thought.

Regards,
Bill K.