#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    22
    Rep Power
    0
    i'm trying to do a task but want to make as simple as possible. i have a large table in mysql which i want analyzing. I have some data for example:
    Name Age Street
    --------------------------
    bob 21 Queens
    gerald 11 Angus
    kevin 42 Queens

    I want to get, in order, the total age of each person living in each street.
    If i was doing the complete thing the sql would go:
    select name,sum(age) from [table name] order by age.
    I could also do 'where street=queens' but with so many records this could take much time. Is there an easier way using sql or not?
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    There's no point in selecting name as it won't return a value if you want the total age of everyone on a street. What you want will work like this:

    select street,sum(age) as t_age group by street order by t_age;

Similar Threads

  1. SQL Statement Help
    By CrazyeD in forum ASP Programming
    Replies: 1
    Last Post: January 26th, 2004, 03:09 PM
  2. sql UPDATE table
    By imustgo in forum ASP Programming
    Replies: 3
    Last Post: November 11th, 2003, 09:28 AM
  3. Poor SQL Server Programming, Part 4
    By DavidM in forum MS SQL Development
    Replies: 0
    Last Post: October 21st, 2003, 10:28 PM
  4. Poor SQL Server Programming Part 2
    By DavidM in forum MS SQL Development
    Replies: 0
    Last Post: October 20th, 2003, 10:19 PM
  5. Poor SQL Server Programming!
    By DavidM in forum MS SQL Development
    Replies: 0
    Last Post: October 20th, 2003, 10:19 PM

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo