SQL question

Discussion in 'OT Technology' started by Homeless, Mar 9, 2008.

  1. Homeless

    Homeless New Member

    Joined:
    Jun 20, 2004
    Messages:
    975
    Likes Received:
    0
    Location:
    NY
    I have a table that lists the name of the person who did a particular task and I cannot figure out how to list the amount of times the persons name appears numerically. I know how to list all the names, just not how to list them numerically.

    So for example lets say I have a table called work and inside there's a group called names.

    SELECT Work.Names
    FROM Work
    ORDER BY Work.Names;

    Using that it will show me how many times in alphabetical order that a name appears inside the table. My goal is to display that numerically, so it will say something like bob - 1 or something of the nature.
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    Code:
    SELECT DISTINCT
      `w`.`Names` AS `Names`,
      (
        SELECT
          COUNT(*)
        FROM
          `Work`
        WHERE
          `Names` = `w`.`Names`
      ) AS `Count`
    FROM
      `Work` w
    ORDER BY
      `w`.`Names` ASC;
     
  3. Homeless

    Homeless New Member

    Joined:
    Jun 20, 2004
    Messages:
    975
    Likes Received:
    0
    Location:
    NY
    That is beyond anything I have learned so far, but thank you very much as it works exactly as I wanted it.
     
  4. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Code:
    SELECT Work.Names, count(*)
    FROM Work
    GROUP BY Work.Names
    ORDER BY Work.Names;
    
     
  5. Homeless

    Homeless New Member

    Joined:
    Jun 20, 2004
    Messages:
    975
    Likes Received:
    0
    Location:
    NY
    That suits my level a bit more, thank you very much.
     

Share This Page