Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loops and querys

    I need to be able to get a report out of my table, but iM having trouble getting my head around it.
    the table gathers info about age
    tabel 'Members'
    -15
    15-24
    25-34
    35-44
    45-64
    65+

    and policy
    Cancer
    Mental Health
    Cardiovascular Health
    Injury Poisoning
    Injury Poisoning

    I need to sumurise and total all members in each age bracket
    against the policy
    -15 ---- Cancer ---- '2'
    15-24 -- Cancer --- '3'
    25-34 -- Cancer --'6'
    etc etc
    15 --Mental health -- '2'
    25-24 Mental Health --'2'

    get the idea
    so wahts the best way to do this?
    Last edited by dawilis; 11-08-2003 at 05:17 AM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    SELECT ageColumnName, COUNT(ageColumnName) AS numPeople, policyColumnName FROM MemberTableName GROUP BY ageColumnName, numPeople, policyColumnName


    that would get you started....
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for age use.... wouldn't it be easier for you to create a value for a range of ages when the age is submitted in the first place?

    like:

    Code:
    if age<15 then
    ageRange=1
    end if
    
    if (age<=15) AND (age<=24) then
    ageRange=2
    end if
    ............
    you can still store the age of the user in a column like "ageExact" and its age range in a column like "ageRange" (which would make it easier for sql use)... I don't know if that post can help actually, maybe that you already do it and that I didn't get it. I guess the sql statement that wrote A1ien51 will maybe be easier for you to make work properly if you do that first since you'll only have to use a single number for your request (for example, 3 would mean people between 25 and 34).
    Last edited by jeskel; 11-08-2003 at 08:38 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •